vbscript 将 html 个文件转换为 docx
vbscript to convert html files to docx
我在 c:\temp\ 中有很多 html 个文件,需要在同一目录中将其转换为 .docx 文件。
我有 Office 2013。所以我猜它不需要任何转换器,而是只在后台打开 html 并将其保存为 .docx。
我找到了一个将 doc 转换为 pdf 的脚本:
vbscript to convert word doc to pdf
Const wdExportAllDocument = 0
Const wdExportOptimizeForPrint = 0
Const wdExportDocumentContent = 0
Const wdExportFormatPDF = 17
Const wdExportCreateHeadingBookmarks = 1
if Wscript.Arguments.Count > 0 Then
' Get the running instance of MS Word. If Word is not running, Create it
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err <> 0 Then
Set objWord = CreateObject("Word.Application")
End If
On Error GoTo 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(WScript.Arguments(0))
Set objDoc = objWord.Documents.Open(WScript.Arguments(0),,TRUE)
'Export to PDF using preferred settings
pdf = objWord.ActiveDocument.ExportAsFixedFormat( _
WScript.Arguments(1), _
wdExportFormatPDF, False, wdExportOptimizeForPrint, _
wdExportAllDocument,,, _
wdExportDocumentContent, _
False, True, _
wdExportCreateHeadingBookmarks _
)
'Quit MS Word
objWord.DisplayAlerts = False
objWord.Quit(False)
set objWord = nothing
set objFSO = nothing
Else
msgbox("You must select a file to convert")
End If
将常量 wdExportFormatPDF 更改为 wdFormatDocumentDefault = 16 会引发错误。
知道如何打开和另存为 c:\temp 目录中的所有文件吗?
The ExportAsFixedFormat method saves a document as PDF or XPS format..
了解更多信息 here。
要将文件保存为 docx
,只需使用 SaveAs method。
它适用于 Office 2013 及更高版本
objWord.ActiveDocument.SaveAs ("C:\SomeDir\yourFileName.docx")
我在 c:\temp\ 中有很多 html 个文件,需要在同一目录中将其转换为 .docx 文件。
我有 Office 2013。所以我猜它不需要任何转换器,而是只在后台打开 html 并将其保存为 .docx。
我找到了一个将 doc 转换为 pdf 的脚本:
vbscript to convert word doc to pdf
Const wdExportAllDocument = 0
Const wdExportOptimizeForPrint = 0
Const wdExportDocumentContent = 0
Const wdExportFormatPDF = 17
Const wdExportCreateHeadingBookmarks = 1
if Wscript.Arguments.Count > 0 Then
' Get the running instance of MS Word. If Word is not running, Create it
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err <> 0 Then
Set objWord = CreateObject("Word.Application")
End If
On Error GoTo 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(WScript.Arguments(0))
Set objDoc = objWord.Documents.Open(WScript.Arguments(0),,TRUE)
'Export to PDF using preferred settings
pdf = objWord.ActiveDocument.ExportAsFixedFormat( _
WScript.Arguments(1), _
wdExportFormatPDF, False, wdExportOptimizeForPrint, _
wdExportAllDocument,,, _
wdExportDocumentContent, _
False, True, _
wdExportCreateHeadingBookmarks _
)
'Quit MS Word
objWord.DisplayAlerts = False
objWord.Quit(False)
set objWord = nothing
set objFSO = nothing
Else
msgbox("You must select a file to convert")
End If
将常量 wdExportFormatPDF 更改为 wdFormatDocumentDefault = 16 会引发错误。
知道如何打开和另存为 c:\temp 目录中的所有文件吗?
The ExportAsFixedFormat method saves a document as PDF or XPS format..
了解更多信息 here。
要将文件保存为 docx
,只需使用 SaveAs method。
它适用于 Office 2013 及更高版本
objWord.ActiveDocument.SaveAs ("C:\SomeDir\yourFileName.docx")