无法从Excel VBA添加新的ppt幻灯片,错误429
我正在研究一个主题,需要将Excel数据导出到PowerPoint中。在我只有一张幻灯片之前,一切都很顺利。但当我尝试添加另一张幻灯片时,它显示错误: 运行时错误429:活动x组件无法创建对象 这是我的密码:无法从Excel VBA添加新的ppt幻灯片,错误429,vba,excel,powerpoint,Vba,Excel,Powerpoint,我正在研究一个主题,需要将Excel数据导出到PowerPoint中。在我只有一张幻灯片之前,一切都很顺利。但当我尝试添加另一张幻灯片时,它显示错误: 运行时错误429:活动x组件无法创建对象 这是我的密码: Dim pptSlide As Slide Dim pptLayout As CustomLayout 'my code Set pptLayout = ActivePresentation.Slides(1).CustomLayout 'error at this line Set
Dim pptSlide As Slide
Dim pptLayout As CustomLayout
'my code
Set pptLayout = ActivePresentation.Slides(1).CustomLayout 'error at this line
Set pptSlide = ActivePresentation.Slides.AddSlide(2, pptLayout)
我不知道它有什么问题。当幻灯片组中有一张幻灯片时,该代码对我来说运行正常,但当幻灯片组中没有幻灯片时,它当然会失败,因为它引用幻灯片1以获取对其自定义布局的引用
Dim pptSlide As Slide
Dim pptLayout As CustomLayout
'my code
With ActivePresentation
' If the deck has some slides, get a freference to the first slide's custom layout
If .Slides.Count > 0 Then
Set pptLayout = .Slides(1).CustomLayout 'error at this line
Else
' If no slides in the deck, use the second custom layout from the master
' (usually the Title and Content layout
Set pptLayout = .SlideMaster.Design.SlideMaster.CustomLayouts(2)
End If
Set pptSlide = .Slides.AddSlide(.Slides.Count + 1, pptLayout)
End With
嘿,
我也犯了同样的错误。
复制幻灯片时,它将成为幻灯片。您只需从以下范围中选择第一项:
Dim spptRange As SlideRange
Dim sppt As PowerPoint.Slide
Set spptRange = PPApp.ActivePresentation.Slides(spptNr).Duplicate
Set sppt = spptRange.Item(1)
如果从PowerPoint本身运行,则代码可以工作。您是使用晚绑定还是早绑定?Ie,您是否设置了对PowerPoint的引用?作为测试,尝试将变量暗显为对象。是的,我引用了PowerPoint。从PowerPoint中运行代码是什么意思@SteveRindsbergI的意思是我在PowerPoint中运行了您的代码,以验证它是否按预期工作。当您从另一个程序中自动化PPT时,有时在Powerpoint中调试PPT部分会更简单、更快。您好,尝试将您的代码集成到我的代码中。仍然给出相同的错误。在使用Active Presentation的
行中,也许您应该包含更多的代码,而不仅仅是您目前提供的代码片段。当我添加opptap.ActivePresentation时,它会起作用。但新添加的幻灯片与上一张幻灯片的布局不同。这是一张有标题的空白幻灯片。如何获得与上一张幻灯片完全相同的格式。Set-pptSlide=opptap.ActivePresentation.Slides(1)。复制对我来说很好,但会出现类型不匹配错误。有什么想法吗?