在下面的代码中使用.copychart
从Excel粘贴到Word错误。如果两个应用程序都是可见的,就像我在编程时已经有了它们一样,那么它运行良好。
有没有办法隐藏应用程序(让它们在后台运行)并仍然使用.copychart
或者我是否需要不同的解决方案?
我只显示代码的一小部分,因为整个模块非常大。这是我在.copypicture
行上收到错误的地方:
'Copy charts to Worddocument
Dim cht1 As Chart, cht2 As Chart, cht3 As Chart
With tbl2
cht1.CopyPicture Appearance:=xlScreen, Format:=xlPicture
With .cell(4, 1).Tables(1).cell(2, 1).Range
.Paste 'Paste NetRevenue Graph
.InlineShapes(1).ScaleWidth = 100
End With
End With
答案 0 :(得分:1)
您可以尝试一些选项:
Word :
如果你有
Dim wordApp As Word.Application
Dim wordDoc As Word.Document
1
wordApp.Visible = False
'...copy chart
wordApp.Visible = True
2
wordDoc.Windows(1).WindowState = wdWindowStateMinimize
'...copy chart
wordDoc.Windows(1).WindowState = wdWindowStateMaximize 'or wdWindowStateNormal
Excel :
1
Application.Visible = False
'...copy chart
Application.Visible = True
2
ActiveWorkbook.Windows(1).WindowState = xlMinimized
'...copy chart
ActiveWorkbook.Windows(1).WindowState = xlMaximized
3
Application.ScreenUpdating = False
'...copy chart
Application.ScreenUpdating = True