【发布时间】:2013-05-08 16:14:02
【问题描述】:
好的,所以我有了这个 Word 2010 启用宏的模板和我方便的花花公子表格,人们可以填写这些表格。我创建了一个按钮,上面写着“转换为 PDF”,因为人们不知道如何在本地进行。我进入了我想要具有此功能的特定 CommandButton 的 VB 编辑器。这是该按钮中的内容:
Private Sub CommandButton1_Click()
Sub Convert_PDF()
Dim desktoploc As String
Dim filename As String
Dim mypath As String
desktoploc = CreateObject("WScript.Shell").SpecialFolders("Desktop")
filename = ThisDocument.Name
mypath = desktoploc & "\" & filename
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
mypath, _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
End Sub
End Sub
当我运行代码时,我得到...... BAM!编译错误:预期结束子
如果我取出 Sub Convert_PDF() 及其相关的 End Sub,突然我没有收到 sub 错误消息,但我收到另一个错误消息:
The file [file name] cannot be opened beacause there are problems with the contents. Details: The file is corrupt and cannot be opened. 将 [file name] 替换为我的文件的实际名称。
老实说,我在 VB 是个十足的 n00b,而到目前为止,Google 的帮助并不大:/
有什么见解吗?
【问题讨论】:
-
我认为您需要创建一个 PDF 对象。当我几年前尝试做类似的事情时,他们没有任何免费的库来帮助解决这个问题。作为一种解决方法(直到我能看到我能找到什么),您可以打印到 pdf 打印机并让您的宏调用它。
-
@Jeff - Excel 2010 具有内置的另存为 PDF:无需其他库...
-
你有两个嵌套的 subs - 这不是有效的 VBA。
标签: vba ms-word word-2010 export-to-pdf commandbutton