通过vba代码将word转换为PDF

需要传两个参数,word路径和pdf路径。
代码可以做成wsf文件,通过C语言或者java调用

<job id="wtop">
<reference guid="{00020905-0000-0000-C000-000000000046}" comment="MSWord 2000 tag library,under HKEY_CLASSES_ROOT\TypeLib\"/>
<script language="VBScript">

Option Explicit

Dim Home_file 
Dim outdoc_file 

'If WScript.Arguments.Count < 2 Then
'	MsgBox "Usage: t1 <Home_file> <outdoc_file> "
'	WScript.Quit
'End If

Home_file = WScript.Arguments(0)
outdoc_file = WScript.Arguments(1)

Dim WordApp
Set WordApp = CreateObject("Word.Application")

With WordApp
	.Visible = False '设置word为可见
	With .Options
		.CheckSpellingAsYouType = False '不检查拼写
		.CheckGrammarAsYouType = False '不检查语法
	End With
	'打开模板文件
	.Documents.Open(Home_file)
	.Documents(1).Activate '激活文档
	Dim doc
	Set doc = .ActiveDocument '得到这个使用中的文件
	
	doc.ExportAsFixedFormat outdoc_file, 17, False, 0, 0, 1, 1, 0, True, True, 0, True, True, False

	doc.Close False
	With .Options
		.CheckSpellingAsYouType = True
		.CheckGrammarAsYouType = True
	End With
	.Quit
	
End With
</script>
</job>
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
您好!感谢您的提问。下面是使用Word中的VBA批量将多个文档转换PDF的步骤: 1. 首先,打开一个新的Word文档,然后按下“Alt+F11”进入VBA编辑器。 2. 在VBA编辑器中,选择“插入”->“模块”,然后将以下VBA代码粘贴到新建的模块中: ``` Sub ConvertToPDF() Dim MyPath As String Dim MyFile As String Dim Doc As Document '选择需要转换的文件夹 With Application.FileDialog(msoFileDialogFolderPicker) .Title = "选择需要转换的文件夹" .Show If .SelectedItems.Count = 0 Then Exit Sub MyPath = .SelectedItems(1) End With '开始循环转换 MyFile = Dir(MyPath & "\*.docx") Do While MyFile <> "" Set Doc = Documents.Open(MyPath & "\" & MyFile) Doc.ExportAsFixedFormat OutputFileName:= _ Replace(MyFile, ".docx", ".pdf"), _ ExportFormat:=wdExportFormatPDF, _ OpenAfterExport:=False, _ OptimizeFor:=wdExportOptimizeForPrint, _ Range:=wdExportAllDocument, _ Item:=wdExportDocumentContent, _ IncludeDocProps:=True, _ KeepIRM:=True, _ CreateBookmarks:=wdExportCreateNoBookmarks, _ DocStructureTags:=True, _ BitmapMissingFonts:=True, _ UseISO19005_1:=False Doc.Close wdDoNotSaveChanges MyFile = Dir Loop MsgBox "转换完成!" End Sub ``` 3. 然后按下“F5”运行代码。 4. 在弹出的文件夹选择对话框中,选择需要转换的文件夹,然后点击“确定”。 5. 程序将会自动将该文件夹下所有的.docx文件转换为.pdf文件,并保存在原文件夹中。 注意:如果您需要转换其他格式的文件,只需要将代码中“.docx”改为其他文件格式即可。 希望这个步骤可以帮到您,如果还有其他问题,请随时联系我。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值