以下是VBA函数,用于从Excel中的工作表复制图表并将其粘贴到powerpoint中。但是,此代码会出现错误" 无效的枚举类型"。 错误在PPApp.ActiveWindow.ViewType = ppViewSlide行中。 请帮助。
Public Function copy_chart1(sheet, slide, group_name, ht, wdt, lf, tp)
Dim PPApp As Object
Dim PPPres As Object
Dim PPSlide As Object
Set PPApp = CreateObject("PowerPoint.Application")
Set PPApp = GetObject(, "Powerpoint.Application")
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
PPApp.ActiveWindow.View.GotoSlide (slide)
Worksheets(sheet).Activate
ActiveSheet.Shapes(group_name).CopyPicture
Set PPSlide = PPPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
With PPSlide
' paste and select the chart picture
.Shapes.Paste.Select
With PPApp.ActiveWindow.Selection.ShapeRange
.LockAspectRatio = msoFalse
.Height = ht
.Width = wdt
.Left = lf
.Top = tp
End With
End With
' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End Function
答案 0 :(得分:1)
如果您是Late Binding
,则需要将所有PPt常量替换为其数值。
PPApp.ActiveWindow.ViewType = 1 '~~> equivalent of ppViewSlide