这是我的代码的一部分,该代码将数据从Excel粘贴到PowerPoint。通常它可以正常工作,但是偶尔(可能在10或20次演练之后,每一次都有大约15个PasteSpecials
相同类型),我收到错误消息:“形状(未知成员):无效的请求。数据类型不可用。”调试器指向行mySlide.Shapes.PasteSpecial DataType:=2
。有人可以弄清楚为什么吗?
如果您要问我为什么使用这种数据类型,我只能说是因为它有效。我尝试了一下,似乎可以将Excel中看到的内容准确地复制到PowerPoint(其他“忘记了”边框等)。
Sub MReport()
Dim rng As Range, rngAn As Range
Dim myShape As PowerPoint.Shape
Dim DestinationPPT As String
Dim lRow As Long, lCol As Long
Dim wbM As Workbook
Dim wsEm As Worksheet
Dim CSGSheet As Variant, CSGSheets As Variant
Dim MonthNum As String, YearNum As String
Set PowerPointApp = New PowerPoint.Application
DestinationPPT = "C:\VBA\ReportTemplate.pptm"
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)
YearNum = "2019"
MonthNum = "02"
Set wbM = Workbooks.Open("C:\VBA\" & YearNum & "\" & Right(YearNum, 2) & "_" & MonthNum & "\NumbersM_" & YearNum & "_" & MonthNum & ".xlsm", UpdateLinks:=False)
CSGSheets = Array("CSG_BM", "CSG_AR", "CSG_ISF")
For Each CSGSheet In CSGSheets
lRow = wbM.Sheets(CSGSheet).Cells(Rows.Count, "B").End(xlUp).End(xlUp).End(xlUp).Row + 1
lCol = wbM.Sheets(CSGSheet).Cells(lRow - 1, "B").End(xlToRight).Column + 1
Set rng = wbM.Sheets(CSGSheet).Range(wbM.Sheets(CSGSheet).Cells(2, 2), wbM.Sheets(CSGSheet).Cells(lRow, lCol))
rng.Copy
Set mySlide = myPresentation.Slides.Add(myPresentation.Slides.Count + 1, 12)
PowerPointApp.ActiveWindow.ViewType = ppViewNormal
mySlide.Shapes.PasteSpecial DataType:=2 '2 = ppPasteEnhancedMetafile
Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
With myShape
.Height = 410
.Top = 70
.Left = 5
End With
Next
wbM.Close SaveChanges:=False
End Sub