将powerpoint演示文稿保存为vba中的pdf

时间:2017-11-22 22:50:47

标签: vba pdf powerpoint powerpoint-vba

我已经查看了很多这个问题的答案,但无法弄清楚我做错了什么。我正在尝试创建一个pdf文件。我从excel文件中获取数据并将其复制到powerpoint中。然后我尝试保存为pdf,但它一直在宏的保存pdf部分给我一个错误(需要对象)(见下文)。我尝试多次更改但仍无法使其正常工作。附上下面的代码。解决这个问题之后,我需要能够改变我粘贴的对象的大小 - 我该怎么做。

Sub CreatePDFfiles_4()


Dim PPapp As Object
Dim PPPres As Object
Dim first_file As Boolean
Dim investorname As String
Dim path As String


Sheets("printing").Select
Range("g2").Select
file1 = ActiveCell.Value
Range("g3").Select
path = ActiveCell.Value
Range("g8").Select
investorname = ActiveCell.Value
Range("i8").Select
cor_file_name = ActiveCell.Value
DestinationPPT = "C:\Users\name\Documents\company\Investment Model\printing macro\template.pptx"


While investorname <> "end"
    ActiveCell.Offset(0, -1).Select
    print_data = ActiveCell.Value
    If print_data = "Yes" Then

        ' Initialize PowerPoint Object Library
        Set PPapp = CreateObject("Powerpoint.Application")
        PPapp.Visible = True

        ' Open presentation
        Set PPPres = PPapp.Presentations.Open(DestinationPPT)

        'Copy excel file data
        Windows(file1).Activate
        Sheets(investorname).Select
        Range("b1:r46").Select
        Selection.Copy

        'Paste into existing powerpoint template slide that is open
        PPPres.slides(1).Shapes.Paste

        'Save as pdf
        PPPres.ExportAsFixedFormat ActivePresentation.path & "\" & cor_file_name & ".pdf", ppFixedFormatTypePDF, ppFixedFormatIntentPrint



        PPapp.Quit
        Set PPapp = Nothing

1 个答案:

答案 0 :(得分:0)

没有一个对我有用。就像这样简单:

file_name = (path and name of the file you want to open)
Path = (where you want to save it)
PdfFileNm = (name of the file)

Set PPT = CreateObject("PowerPoint.Application")
Set Pres = PPT.presentations.Open(file_name)
PPT.ActivePresentation.SaveAs Path & PdfFileNm & ".pdf", 32