使用VBA代码如何在Excel 2003中将excel工作表导出为图像?
问题描述:
请建议使用excel工作表将数据导出的更好方式以.jpeg或.png或.gif格式导出。
Please suggest the better way of exporting range of data from excel worksheets as image either in .jpeg or .png or in .gif.
答
你想尝试以下代码,我在互联网上发现许多月前和使用的地方。
do you want to try the below code I found on the internet somewhere many moons ago and used.
它使用Chart对象的导出功能使用Range对象的CopyPicture方法。
It uses the Export function of the Chart object along with the CopyPicture method of the Range object.
参考文献:
- MSDN - 导出方法适用于Chart对象。将剪贴板保存为图像
-
MSDN - CopyPicture方法适用于Range对象将范围复制为图片
- MSDN - Export method as it applies to the Chart object. to save the clipboard as an Image
MSDN - CopyPicture method as it applies to the Range object to copy the range as a picture
dim sSheetName as string
dim oRangeToCopy as range
Dim oCht As Chart
sSheetName ="Sheet1" ' worksheet to work on
set oRangeToCopy =Range("B2:H8") ' range to be copied
Worksheets(sSheetName).Range(oRangeToCopy).CopyPicture xlScreen, xlBitmap
set oCht =charts.add
with oCht
.paste
.Export FileName:="C:\SavedRange.jpg", Filtername:="JPG"
end with