我正在尝试从excel复制范围,然后添加一张幻灯片并粘贴复制的范围。
我在Powerpoint.App.ActiveWindow.Activate行出现错误,说未设置Object变量或With块变量。请让我知道是否有更好的方法将幻灯片添加到所选的Powerpoint。谢谢!这也是我的第一篇博文,我是代码的新手,请让我知道其他任何技巧,谢谢。
'open powerpoint
Dim intChoice as Integer
Dim strPath As String
Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
Call Application.FileDialog(msoFileDialogOpen).Filters.Add ( _ "PowerPoint Files Only", "*.ppt; *.pptx")
intChoice=Application.FileDialog(msoFileDialogOpen).Show
If intChoice <> 0 Then
strPath=Application.FileDialog ( _ msoFileDialogOpen).SelectedItems(1)
Cells (1,1) = strPath
End If
If intChoice = 0 Then
MsgBox "A file must be selected to complete"
End
End If
'copy graph
Worksheets("Graph").Activate
Range ("M1:CA32").Select
Selection.Copy
'add slide
Dim myPresentation As Object
Dim mySlide As Object
Dim PowerpointApp As Object
Dim shp As Object
PowerpointApp.ActiveWindow.Panes(2).Activate
Set myPresentation=PowerpointApp.ActivePresentation
myPresentation.Add.Slide(1)
'paste graph onto first slide, add title, Resize
Set shp=PowerpointApp.ActiveWindow.Selection.ShapeRange
With myPresentation.PageSetup
shp.Left=3
shp.Top=72
shp.Width=714
End With