VBA即用型代码手册:利用函数保存为PDF文件UseFunctionSaveAsPDF
我给VBA下的定义:VBA是个人小型自动化处理的有效工具。可以大大提高自己的劳动效率,而且可以提高数据的准确性。我这里专注VBA,将我多年的经验汇集在VBA系列九套教程中。
作为我的学员要利用我的积木编程思想,积木编程最重要的是积木如何搭建及拥有积木。在九套教程中我给出了大量的积木,同时讲解了如何搭建。为了让学员拥有更多的积木,我开始着手这部《VBA即用型代码手册(汉英)》的创作,这部手册约600页,集合约500多个的案例,案例我用汉语和英语同时发布,一方面学员从中可以更好的领会和掌握VBA中用到的一些英语知识,另一方面,大家可以看到各种各样的积木。这部手册是大家学习和工作中的不可多得的实用资料。今日的内容是: VBA即用型代码手册:利用函数保存为PDF文件Use Function SaveAsPDF 
【分享成果,随喜正能量】334其实人与人之间都是相互的,你为别人铺路,别人为你搭桥,你给别人难堪,别人给你添堵,真正有智慧的人都明白,人生是相互成全的。
第六章 Word对象及示例
Word Objects and Macro Examples
11 利用函数保存为PDF文件Use Function SaveAs PDF
Sub mynzCallSaveAsPDF()
Call MacroSaveAsPDFwParameters("C:\Users\Public\Documents", "example.docx")
End Sub
Sub MacroSaveAsPDFwParameters(Optional strPath As String, Optional strFilename As String)
If strFilename = "" Then
strFilename = ActiveDocument.Name
End If
'extract just file name without extension
If InStr(1, strFilename, ".") > 0 Then
strFilename = Left$(strFilename, InStrRev(strFilename, ".") - 1)
End If
If strPath = "" Then
If ActiveDocument.Path = "" Then
strPath = Options.DefaultFilePath(wdDocumentsPath) & Application.PathSeparator
Else
strPath = Options.DefaultFilePath(wdDocumentsPath) & Application.PathSeparator
End If
End If
On Error GoTo EXITHERE
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
strPath & strFilename & ".pdf", _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, _
IncludeDocProps:=True, _
CreateBookmarks:=wdExportCreateWordBookmarks, _
BitmapMissingFonts:=True
Exit Sub
EXITHERE:
MsgBox "Error: " & Err.Number & " " & Err.Description
End Sub

- 本节内容参考程序文件:Chapter06.docm

我20多年的VBA实践经验,全部浓缩在下面的各个教程中:


