【分享成果,随喜正能量】请保持心中的善良,因为也许有一天,就会有人借着你的善良,感受到温暖,走出绝望。。
我给VBA的定义:VBA是个人小型自动化处理的有效工具。利用好了,可以大大提高自己的劳动效率,而且可以提高数据的准确度。我推出的VBA系列教程共十套(本文的最后附有VBA教程目录和VBA工具目录),现在已经全部完成。
如果您VBA是入门阶段,可以选择7.1.3.9教程,第7套教程是入门,第1套教程是入门后的提高,第3套教程字典是必备的VBA之精华,第9套教程是实用的典型案例讲解。如果您有了一定的VBA基础可以根据自己的需要,进行教程的选择。教程提供的程序源码文件就如一座大型的代码库支持着大家的工作。同时还有实用的资料送给学员。
VBA是面向对象编程的语言,博大精深。很多朋友咨询英语和VBA的关系,这套《VBA即用型代码手册(汉英)》集合了众多的案例,案例我用汉语和英语同时发布,学员从中可以更好的领会和掌握VBA中用到的一些英语。今日的内容:将文档保存为PDF文件
第六章 Word对象及示例
Word Objects and Macro Examples
9 创建一个新文档并保存html文件 Create and SaveAs Html FileSub mynzCreateAndSaveAs()
'创建一个新文档并保存为过滤后的 html [在默认文件夹中并以当前时间命名]
Dim strTime As String
Dim strPath As String
Dim oDoc As Document
strPath = ActiveDocument.Path & Application.PathSeparator
strTime = Format(Now, "yyyy-mm-dd hh-mm")
Set oDoc = Documents.Add 'create a new doc and asign it to oDoc variable
'write some text in the new doc reffering to it using oDoc variable
oDoc.Range.InsertBefore "VBA"
oDoc.SaveAs FileName:=strPath & strTime, FileFormat:=wdFormatFilteredHTML
oDoc.Close wdDoNotSaveChanges 'close doc
End Sub
10 保存为PDF文件SaveAs PDF
Sub mynzMacroSaveAsPDF()
'宏将pdf保存在活动文档所在的同一文件夹中,如果文件尚未保存,则保存在文档文件夹中
Dim strPath As String
Dim strPDFname As String
strPDFname = InputBox("Enter name for PDF", "File Name", "example")
If strPDFname = "" Then
strPDFname = "example"
End If
strPath = ActiveDocument.Path
If strPath = "" Then
strPath = Options.DefaultFilePath(wdDocumentsPath) & Application.PathSeparator
Else
strPath = strPath & Application.PathSeparator
End If
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
strPath & strPDFname & ".pdf", _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, _
IncludeDocProps:=True, _
CreateBookmarks:=wdExportCreateWordBookmarks, _
BitmapMissingFonts:=True
End Sub
【分享成果,随喜正能量】我20多年的VBA实践经验,全部浓缩在下面的各个教程中:
【分享成果,随喜正能量】人活着,放下衡量别人的心,也放过总在盲目追逐的自己,不用强行去为他人点灯,只要发自己的光就好。。
,