简体   繁体   English

ActiveX无法创建对象Powerpont VBA

[英]ActiveX can't create object powerpont vba

I am trying to copy 1st slide from the powerpoint and insert it at the end but I am getting ActiveX can't create object on the line 我正在尝试从PowerPoint复制第一张幻灯片并将其插入到末尾,但我得到ActiveX无法在行上创建对象

ActivePresentation.Slides(1).Copy

This is my full code and I've added the reference to microsoft powerpoint library as well 这是我的完整代码,并且我已经将引用添加到Microsoft Powerpoint库中

Option Explicit

Dim myFile, Fileselected As String, Path As String, objPPT As Object
Dim activeSlide As PowerPoint.Slide

Sub Generate_PPTs()

Application.ScreenUpdating = False

Set myFile = Application.FileDialog(msoFileDialogOpen)
With myFile
    .Title = "Choose Template PPT File."
    .AllowMultiSelect = False
If .Show <> -1 Then
    Exit Sub
End If
    Fileselected = .SelectedItems(1)
End With
Path = Fileselected

Set objPPT = CreateObject("PowerPoint.Application")
Set objPPT = objPPT.Presentations.Open(Path)

Debug.Print objPPT.Name

ActivePresentation.Slides(1).Copy
ActivePresentation.Slides.Paste Index:=objPPT.Slides.Count + 1

Set activeSlide = objPPT.Slides(objPPT.Slides.Count)

Application.ScreenUpdating = True
Set objPPT = Nothing

End Sub

Try edited code below, I have ppApp As PowerPoint.Application and Dim ppPres As PowerPoint.Presentation : 尝试在下面编辑代码,我将ppApp As PowerPoint.Application ,将ppApp As PowerPoint.Application Dim ppPres As PowerPoint.Presentation

Option Explicit

Dim myFile, Fileselected As String, Path As String, objPPT As Object
Dim ppApp   As PowerPoint.Application
Dim ppPres  As PowerPoint.Presentation

Dim activeSlide As PowerPoint.Slide

Sub Generate_PPTs()

Application.ScreenUpdating = False

Set myFile = Application.FileDialog(msoFileDialogOpen)
With myFile
    .Title = "Choose Template PPT File."
    .AllowMultiSelect = False
If .Show <> -1 Then
    Exit Sub
End If
    Fileselected = .SelectedItems(1)
End With
Path = Fileselected

Dim i As Integer

Set ppApp = New PowerPoint.Application
i = 1

ppApp.Presentations.Open Filename:=Path  ' 'PowerPointFile = "C:\Test.pptx"
Set ppPres = ppApp.Presentations.Item(i)

' for debug
Debug.Print ppPres.Name

ppPres.Slides(1).Copy
ppPres.Slides.Paste Index:=ppPres.Slides.Count + 1

Set activeSlide = ppPres.Slides(ppPres.Slides.Count)

Application.ScreenUpdating = True
Set ppPres = Nothing
Set ppApp = Nothing

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM