VBA运行时错误:将PowerPoint演示文稿另存为PDF

克莱门斯·安布罗斯(Clemens Ambros)

我从Excel工作簿(均为2016版)创建Powerpoint演示文稿,最后,我要将演示文稿另存为pdf。

我试过了:

filenamePPT = Environ("UserProfile") & "\Desktop\" & Format(Date, "yyyy_mm_dd") & "_Statusbericht_" & ApName & "_KW" & KW & ".pdf"

ActivePresentation.ExportAsFixedFormat filenamePPT, ppFixedFormatTypePDF

并得到:

运行时错误:-2147221165(80040154):未注册类

在第二行。

我认为,我已根据Microsoft文档进行了所有操作

编辑:

添加了所有相关参考:

  • PowerPoint 16.0对象库
  • OLE自动化
  • Office 16.0对象库
  • Forms 2.0对象库
  • ActiveX数据对象6.1库
  • ActiveX数据对象Recordset 6.0库

编辑2:

Public createslide6 As Boolean
Public ChartrngVONstring As String
Public ChartrngBISstring As String
Public filenameEXCEL As String
Public user As String


Sub VBA_AP_Status_v1()


Dim year As Double
Dim ZKW1 As Double
Dim ZKW2 As Double
Dim ZKW3 As Double
Dim ZKW4 As Double
Dim ZKW5 As Double
Dim ZKW6 As Double
Dim ZKW7 As Double
Dim ZKW8 As Double
Dim MS1Dauer As Double
Dim MS2Dauer As Double
Dim MS3Dauer As Double
Dim MS4Dauer As Double
Dim MS5Dauer As Double
Dim MS6Dauer As Double
Dim MS7Dauer As Double
Dim MS8Dauer As Double
Dim minScale As Double
Dim maxScale As Double
Dim e As Integer
Dim yearString As String
Dim nextyearString As String
Dim StandortVar As String
Dim filenamePPT As String
Dim pptLayout As CustomLayout

Dim AllgShape As Object
Dim MSShape As Object
Dim MSTShape As Object
Dim BemShape As Object
Dim APUShape As Object
Dim LGShape As Object
Dim HLShape As Object
Dim SlideNum As Object
Dim Fußzeile As Object
Dim PowerPointApp As Object
Dim myPresentation As Object
Dim mySlide1 As Object
Dim mySlide2 As Object
Dim mySlide3 As Object
Dim mySlide4 As Object
Dim mySlide5 As Object
Dim mySlide6 As Object
Dim mySlide7 As Object
Dim myShape As Object
Dim ppTextbox As Object
Dim Chart1 As Object
Dim ChartLegend As Object
Dim MSPfeilLang As Object
Dim MSPfeilKurz As Object
Dim MSDreieck1 As Object
Dim MSDreieck2 As Object
Dim MSDreieck3 As Object
Dim MSDreieck4 As Object
Dim MSDreieck5 As Object
Dim MSDreieck6 As Object
Dim RisikenTable As Object



user = Environ("username")
year = Format(Date, "yyyy")
yearString = Format(Date, "yyyy")
nextyearString = Format(Date, "yyyy") + 1


'Create an Instance of PowerPoint
  On Error Resume Next

'Is PowerPoint already opened?
  Set PowerPointApp = GetObject(class:="PowerPoint.Application")

'Clear the error between errors
  Err.Clear

'If PowerPoint is not already open then open PowerPoint
  If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="PowerPoint.Application")

'Handle if the PowerPoint Application is not found
  If Err.Number = 429 Then
    MsgBox "PowerPoint could not be found, aborting."
    Exit Sub
  End If

  On Error GoTo 0

'Optimize Code
  Application.ScreenUpdating = False

'Create a New Presentation
  Set myPresentation = PowerPointApp.Presentations.Add


  myPresentation.ApplyTemplate "C:\Users\" & user & "\AppData\Roaming\Microsoft\Templates\Document Themes\AP_Status_Vorlage.thmx"


'Add slides to the Presentation
  Set mySlide1 = myPresentation.Slides.Add(1, ppLayoutCustom)       'an pos 1     '11 = ppLayoutTitleOnly
  Set mySlide2 = myPresentation.Slides.Add(2, ppLayoutTitleOnly)


  Set ppTextbox = mySlide1.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 80, 800, 80)




~ 2k lines of code were deleted here





filenameEXCEL = "C:\users\" & user & "\Desktop\Daten_Statusbericht_" & ApName & "_KW" & KW & "_" & Format(Date, "dd_mm_yy")
filenamePPT = Environ("UserProfile") & "\Desktop\" & Format(Date, "yyyy_mm_dd") & "_Statusbericht_" & ApName & "_KW" & KW & ".pdf"

'Make PowerPoint Visible and Active // OPTIONAL
  PowerPointApp.Visible = True
  PowerPointApp.Activate

'Clear The Clipboard
  Application.CutCopyMode = False

'SAVING & CLOSING Powerpoint

  ActivePresentation.ExportAsFixedFormat filenamePPT, ppFixedFormatTypePDF

  'If Not GetObject(, "PowerPoint.Application") Is Nothing Then
    'GetObject(, "PowerPoint.Application").Quit
  'End If


'Call CloseAndSaveExcelApplication

End Sub

有什么建议?

悉达思·劳特

将PowerPointApp变暗为对象

将myPresentation设置为对象

将mySlide1昏暗为对象

您已使用后期绑定和早期绑定在一起。尝试这个

Option Explicit

Sub Sample()
    Dim oPPApp As PowerPoint.Application
    Dim oPPPrsn As PowerPoint.Presentation
    Dim oPPSlide As PowerPoint.Slide
    
    Dim FlName As String
    
    '~~> Change this to the relevant file
    FlName = "C:\Users\routs\Desktop\test.pdf"
    
    '~~> Establish an PowerPoint application object
    On Error Resume Next
    Set oPPApp = GetObject(, "PowerPoint.Application")
    
    If Err.Number <> 0 Then
        Set oPPApp = CreateObject("PowerPoint.Application")
    End If
    Err.Clear
    On Error GoTo 0
    
    oPPApp.Visible = True
    
    '~~> Open the relevant powerpoint file
    Set oPPPrsn = oPPApp.Presentations.Add
    
    '~~> Change this to the relevant slide which has the shape
    Set oPPSlide = oPPPrsn.Slides.Add(1, ppLayoutCustom)
    
    oPPPrsn.ExportAsFixedFormat FlName, ppFixedFormatTypePDF
End Sub

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用OpenXML将PowerPoint演示文稿另存为PDF

来自分类Dev

将rmarkdown ioslides演示文稿另存为独立网站

来自分类Dev

Excel另存为运行时

来自分类Dev

运行打开文件并将其另存为值的宏的宏-运行时错误1004

来自分类Dev

Rpres HTML5演示文稿“另存为PDF”(Google Chrome)显示不正确

来自分类Dev

在Windows运行时中将文件缩略图另存为图像

来自分类Dev

动态将段落另存为PDF?

来自分类Dev

将油量图另存为PDF

来自分类Dev

将pdf文件另存为blob

来自分类Dev

将excel另存为pdf,将文件名另存为变量值

来自分类Dev

VBA-忽略隐藏的工作表-将特定的工作表另存为PDF

来自分类Dev

将文档另存为PDF时,VBA超链接不起作用

来自分类Dev

将文件另存为.pdf(如http响应错误所示)

来自分类Dev

VBA 取消另存为

来自分类Dev

如何将网页另存为PDF?

来自分类Dev

通过Excel将pptx另存为pdf

来自分类Dev

imagemagick魔杖将pdf页面另存为图像

来自分类Dev

将Outlook mailitem正文另存为PDF

来自分类Dev

将flot饼图另存为PDF

来自分类Dev

将Outlook电子邮件另存为PDF +附件

来自分类Dev

使用CSS将前置元素另存为PDF

来自分类Dev

将图另存为PDF后,图例变得混乱

来自分类Dev

将元素另存为pdf时添加标题

来自分类Dev

Juypter Notebook:将输出另存为pdf

来自分类Dev

如何将图像PDF文件另存为图像?

来自分类Dev

如何将html文件另存为pdf?

来自分类Dev

使用Python将网页另存为PDF吗?

来自分类Dev

使用Office Lens将文档扫描另存为PDF

来自分类Dev

将图另存为PDF后,图例变得混乱