gpt4 book ai didi

vba - 尝试通过 Excel VBA 宏保存 GIF 屏幕截图时出错

转载 作者:行者123 更新时间:2023-12-01 11:48:04 24 4
gpt4 key购买 nike

我正在使用下面的链接截取 excel 的屏幕截图并另存为 .gif 文件:

http://dmcritchie.mvps.org/excel/xl2gif.htm

当我尝试运行宏时,它在“containerbok.Activate”处出现以下错误:

运行时错误“424”:需要对象

我可以知道为什么会出现此错误吗?

我正在使用 Excel 2010

谢谢!

最佳答案

事情实际上比您发布的链接中的代码要简单一些。只需选择要成像的细胞范围,然后运行以下代码。

 Sub ExportSelection()

If TypeName(Selection) = "Range" Then
'Copy the area that you have selected as a picture.
Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
'Create a default bar(column) chart using the selected cells.
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlColumnClustered
'Remove all the data from the chart, leaving a blank chart.
Dim i As Integer
For i = ActiveChart.SeriesCollection.Count To 1 Step -1
ActiveChart.SeriesCollection(i).Delete
Next
'Paste the image of the selected cells onto the chart.
ActiveChart.Paste
'Export the chart as a gif image.
ActiveChart.Export Environ("USERPROFILE") & "\Desktop\chart.gif"
'Delete the existing chart.
ActiveChart.Parent.Delete
End If

End Sub

关键部分是ActiveChart.Export

这已在 Excel 2010 中测试并且完美运行。

关于vba - 尝试通过 Excel VBA 宏保存 GIF 屏幕截图时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14117819/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com