Word VBA 代码

Word批量转PDF

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Sub 批量()
名称 = Dir("C:\孙兴华\")
Do While 名称 <> ""
Set 文档 = Word.Application.Documents.Open("C:\孙兴华\" & 名称)
路径 = 文档.Path
文档.ExportAsFixedFormat OutputFileName:=(路径 & "\" & 文档.Name & ".pdf"), _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportFromTo, From:=1, To:=文档.Range.Information(wdNumberOfPagesInDocument), _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateHeadingBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True

文档.Save
文档.Close
名称 = Dir
Loop
End Sub

使用Excel公式

1
2
3
4
5
6
7
8
9
Sub 使用公式()
Set 起始位置 = ActiveDocument.Range(0, 0)
Set 表格 = ActiveDocument.Tables.Add(起始位置, 3, 3)
With 表格
.Cell(1, 1).Range.InsertAfter "10"
.Cell(2, 1).Range.InsertAfter "20"
.Cell(3, 1).Formula "=Average(Above)"
End With
End Sub