在 Excel VB 中运行图表/PNG 导出循环时,复制/粘贴在其他应用程序中不起作用
我有一个循环运行来生成 PNG(在 HTML 文件中使用)。运行时,复制/粘贴不适用于计算机上的其他应用程序。有没有办法在 Excel 中进行复制/粘贴?和/或加速这段代码? (其中一些代码是我在其他地方找到的,感谢您的帮助。)谢谢。
Sub ToPNG()
' save a range from Excel as a picture
Dim r As Range
Dim c As ChartObject
Const strPath As String = "C:\G\"
Application.ScreenUpdating = False
Set r = Workbooks("GMon.xlsm").Worksheets("Main").Range("Print_Area")
r.CopyPicture xlScreen, xlPicture
Set c = ActiveSheet.ChartObjects.Add(0, 0, r.Width + 0, r.Height + 7)
c.Chart.Paste
c.Chart.Export strPath & "GMonOut.png", "PNG"
c.Delete
ExitProc:
Application.ScreenUpdating = True
Set c = Nothing
Set r = Nothing
End Sub
I have a loop that runs to generate a PNG (which is used in an HTML file). While running, copy/paste does not work for other applications on the computer. Is there a way to make copy/paste work within excel? and/or speed up this code? (Some of this code I found elsewhere, and appreciate that help.) Thanks.
Sub ToPNG()
' save a range from Excel as a picture
Dim r As Range
Dim c As ChartObject
Const strPath As String = "C:\G\"
Application.ScreenUpdating = False
Set r = Workbooks("GMon.xlsm").Worksheets("Main").Range("Print_Area")
r.CopyPicture xlScreen, xlPicture
Set c = ActiveSheet.ChartObjects.Add(0, 0, r.Width + 0, r.Height + 7)
c.Chart.Paste
c.Chart.Export strPath & "GMonOut.png", "PNG"
c.Delete
ExitProc:
Application.ScreenUpdating = True
Set c = Nothing
Set r = Nothing
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于“每隔几秒”运行的代码正在使用剪贴板,因此它会干扰剪贴板的任何其他用户。
我看到的唯一选择是重写代码,以避免完全使用
Copy
Paste
操作。 (也许通过自动使用第 3 方屏幕捕获实用程序)Since your code that is running "every few seconds" is using the clipboard, it will interfere with any other users of the clipboard.
The only option I see is to rewrite your code to avoid use of
Copy
Paste
operations entirely. (perhaps by automating the use of a 3rd party screen capture utility)