在 vba 中将 powerpoint 演示文稿另存为 pdf

问题描述 投票:0回答:2

我看了这个问题的很多答案,但不知道我做错了什么。我正在尝试创建一个 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
vba pdf powerpoint
2个回答
4
投票

这些对我来说都不起作用。就这么简单:

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

0
投票

您需要按如下方式更新您的代码。它对我有用。

`

' 清除打印范围并将其设置为仅当前幻灯片

ppt.PrintOptions.Ranges.ClearAll
Set pr = ppt.PrintOptions.Ranges.Add(Start:=sld.slideNumber, End:=sld.slideNumber)

' 运行导出 ppt.ExportAsFixedFormat 路径:=folderPath & fn, _ 固定格式类型:=2,_ 范围类型:=1,_ 打印范围:=pr, _ 意图:=1,_ FrameSlides:=msoFalse`

© www.soinside.com 2019 - 2024. All rights reserved.