【问题标题】:EXCEL VBA word to pdf multiple times SaveAs2EXCEL VBA word to pdf多次SaveAs2
【发布时间】:2017-06-26 05:34:59
【问题描述】:

我想用值填充一个单词并多次导出为 pdf。

如果第一次使用 SaveAs2,它会生成 pdf,但第二次或第三次它不起作用。

'ActiveDocument.SaveAs2 FileName:="C:\alap\" & fajlneve & ".pdf", FileFormat:=wdFormatPDF

如果我使用 CutePDf 打印机,结果是一样的,第一次 i=1 有效,但第二次无效。

Public compname As String
Public filename As String


Function FillwordForm()

Dim appword As Word.Application
Dim doc As Word.Document
Dim Path As String


On Error Resume Next
Error.Clear


Set appword = GetObject(, "word.application")
If Err.Number <> 0 Then

Set appword = New Word.Application
appword.Visible = True

End If
Path = "C:\pelda\MINTA.docx"
Set doc = appword.Documents.Open(Path, , True)

With doc

    .formfields("szerzCegnev").result = compname

End With

appword.Visible = True
appword.Activate

Set doc = Nothing
Set appword = Nothing

appword.ActivePrinter = "CutePDF Writer"

ActiveDocument.PrintOut OutPutFileName:="C:\pelda\" & filename & ".pdf"

ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

Word.Application.Quit

End Function


  '---------------------------------------------------------------


Sub cucc()

For i = 1 To 2

compname = Cells(i, 1)
filename = Cells(i, 2)
Call FillwordForm

Next i


End Sub

【问题讨论】:

  • 没有 i 变量。您可能只是每次都覆盖同一个文件..
  • 请准确描述它是如何“不起作用”的。

标签: vba excel pdf ms-word


【解决方案1】:

你能用吗:

    ActiveDocument.SaveAs2(docname,17);

? (17 为 PDF 格式 -link to fileformats)

问候

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    • 2021-05-13
    • 2016-11-22
    • 1970-01-01
    • 1970-01-01
    • 2021-01-04
    相关资源
    最近更新 更多