【问题标题】:VBScript to convert DOC to DOCX without Compatibility Mode enabledVBScript 在不启用兼容模式的情况下将 DOC 转换为 DOCX
【发布时间】:2019-12-13 14:19:30
【问题描述】:

下面我的 VBScript 将 Word DOC 转换为 DOCX:

Set oFSO = CreateObject("Scripting.FileSystemObject")
fullpath = oFSO.GetAbsolutePathName(Wscript.Arguments.Item(0))
justpath = Left(fullpath, InStrRev(fullpath, "\"))
basename = oFSO.GetBaseName(fullpath)
doxpath = justpath & basename & ".docx" 
Set oWord = CreateObject("Word.Application")
Set doc = oWord.Documents.Open(fullpath)
doc.SaveAs2 doxpath, 16
doc.Close
oWord.Quit
Set oFSO = Nothing

但是,当我打开输出 DOCX 时,顶部显示“[兼容模式]”。在 SaveAs2 调用之前/期间/之后,我是否可以设置一些属性或调用方法,以免发生这种情况?

【问题讨论】:

  • 你看过SaveAs2()的文档吗? docs.microsoft.com/en-us/office/vba/api/word.saveas2
  • 是的。但这是一个 VBA 页面,兼容性选项位于一长串参数的末尾,无法在 VBS 中指定命名参数,我不想指定所有参数。
  • 您可以跳过不想提供的可选参数,只需写下相应数量的空逗号:.SomeMethod RequiredArg, , , , , , OptionalArg
  • Niiice。不知道。谢谢!

标签: vbscript ms-word docx doc


【解决方案1】:

现在可以了。谢谢托马拉克!

Set oFSO = CreateObject("Scripting.FileSystemObject")
fullpath = oFSO.GetAbsolutePathName(Wscript.Arguments.Item(0))
justpath = Left(fullpath, InStrRev(fullpath, "\"))
basename = oFSO.GetBaseName(fullpath)
doxpath = justpath & basename & ".docx" 
Set oWord = CreateObject("Word.Application")
Set doc = oWord.Documents.Open(fullpath)
'FileFormat = wdFormatDocumentDefault = 16 = Word default document file format. For Word, this is the DOCX format.
'CompatibilityMode = wdCurrent = 65535 = Compatibility mode equivalent to the latest version of Word.
doc.SaveAs2 doxpath, 16, , , , , , , , , , , , , , , 65535
doc.Close
oWord.Quit
Set oFSO = Nothing

【讨论】:

  • 我倾向于定义Const wdCurrent = 65535 并在其余代码中使用常量。这可以节省解释性注释,并且比方法调用中的幻数更少令人毛骨悚然。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-30
  • 2021-12-05
  • 1970-01-01
  • 2021-08-27
  • 1970-01-01
  • 1970-01-01
  • 2011-06-16
相关资源
最近更新 更多