使用VBA代码如何在Excel 2003中将Excel工作表导出为图像?

Vis*_*til 11 excel vba excel-vba

请建议以更好的方式将excel工作表中的数据范围导出为.jpeg或.png或.gif格式的图像.

Our*_*nas 10

你想尝试下面我在互联网上找到的许多以前和使用过的代码.

它使用Chart对象的Export函数以及Range对象的CopyPicture方法.

参考文献:

  • 在这一行对我有用: Worksheets(sSheetName).Range(oRangeToCopy).CopyPicture xlScreen, xlBitmap (2认同)

Win*_*and 7

我试图通过几种方式改进这个解决方案.现在生成的图像具有正确的比例.

Set sheet = ActiveSheet
output = "D:\SavedRange4.png"

zoom_coef = 100 / sheet.Parent.Windows(1).Zoom
Set area = sheet.Range(sheet.PageSetup.PrintArea)
area.CopyPicture xlPrinter
Set chartobj = sheet.ChartObjects.Add(0, 0, area.Width * zoom_coef, area.Height * zoom_coef)
chartobj.Chart.Paste
chartobj.Chart.Export output, "png"
chartobj.Delete
Run Code Online (Sandbox Code Playgroud)