在 Excel VB 中运行图表/PNG 导出循环时,复制/粘贴在其他应用程序中不起作用

发布于 2024-12-23 09:28:34 字数 701 浏览 6 评论 0原文

我有一个循环运行来生成 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风夜微凉 2024-12-30 09:28:34

由于“每隔几秒”运行的代码正在使用剪贴板,因此它会干扰剪贴板的任何其他用户。

我看到的唯一选择是重写代码,以避免完全使用 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文