我正在使用一个大型宏,代码的一部分将一些单元格复制到图表对象,以便将其保存为.png并将其附加到电子邮件中。切换到Windows 10后,图表对象为空。奇怪的是,如果你在粘贴动作上面添加一个断点,然后恢复宏,一切正常。这让我很难过。我已经检查过剪贴板保存了表,并尝试中断代码来复制断点,似乎没有任何工作。
编辑:
这是失败的代码
Public Sub SaveTableRangeAs(ows As Worksheet, sFolderPath As String, sExtension As String, sRangeName As String)
Dim rng As Range
Dim cht
Set rng = ows.Range(sRangeName)
rng.CopyPicture xlScreen, xlPicture
Set cht = ows.ChartObjects.Add(0, 0, rng.Width, rng.Height)
'adding a breakpoint to line just below this one will result in the function working
With cht
.chart.Paste
.chart.Export sFolderPath & sRangeName & "." & sExtension
.Delete
End With
End Sub