You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Excel VBA粘贴图表为图片时遇运行时错误1004(Win11特定场景)

Excel VBA图表粘贴为图片报错问题

用于生成内部报表的Excel VBA代码部署在SharePoint上,核心功能是将工作表中的图表粘贴为图片到指定位置。

原有VBA代码

ActiveSheet.ChartObjects(Chart_Number).Chart.CopyPicture _
    Appearance:=xlPrinted, Size:=xlScreen, Format:=xlPicture

Sheets(LName & " EMA1").Select
Range("A" & Final_Position).Select
If Chart_Number > 1 Then
    ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
End If

ActiveSheet.PasteSpecial Format:="Picture (Enhanced Metafile)", Link:=False _
    , DisplayAsIcon:=False

注:代码使用了ActiveSheet和Select,也曾尝试其他实现方式,寻求优化建议。

报错详情

执行到ActiveSheet.PasteSpecial时触发报错:

运行时错误 '1004':无法粘贴此数据,耗时过长。请尝试缩小所选内容范围。如果从远程计算机复制,可能是网络性能问题导致。

  • Windows 10设备无此错误
  • 仅部分Windows 11设备会稳定复现该错误

临时解决方法为关闭所有其他Office应用(Word、PowerPoint、Outlook),虽可通过代码在Excel打开时关闭这些应用、关闭Excel时重新打开,但操作繁琐。

尝试的替代代码及问题

尝试改用Shapes.AddPicture实现,却触发“文件未找到”错误:

Dim destinationSheet As Worksheet
Dim destinationRange As Range
Dim destinationShape As Shape

Set destinationSheet = ThisWorkbook.Worksheets(LNAME & " EMA1") 
Set destinationRange = destinationSheet.Range("A" & Final_Position) 
Set destinationShape = destinationSheet.Shapes.AddPicture("", False, True, destinationRange.Left, destinationRange.Top, destinationRange.Width, destinationRange.Height)

内容的提问来源于stack exchange,提问作者Christi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 22:12:30