0

我需要打开大量当前保存在 Publisher(2003、2007 和 2010)中的文档并将它们转换为 Word 文档。这些是简单的一页文本文档,但我有大约 1,000 个要转换。这是我的代码:

Public Sub Pub_To_Word()

Dim FS As New FileSystemObject
Dim pubApp As Publisher.Application
' Reference Library pointing to:
' Microsoft Scripting Runtime
' Microsoft Word 14.0 Object Library
Dim FSfolder As Folder
Dim MyFile As File
Dim mydoc As Document
Dim sFolderPath As String
Dim Table As Table


sFolderPath = "I:\My Documents\Publisher Test"
Set FSfolder = FS.GetFolder(sFolderPath)

For Each MyFile In FSfolder.Files

           Set mydoc = pubApp.Open(MyFile)
               Application.DisplayAlerts = False
               mydoc.SaveAs Filename:MyFile & ".docx", FileFormat:=wdFormatXMLDocument
               mydoc.Close savechanges:=True
           pubApp.DisplayAlerts = True

      End If

     Next

    End
End Sub

代码调试在

 FileFormat:=wdFormatXMLDocument

我似乎无法超越这一点。

4

1 回答 1

0

不知道你为什么在 Excel 中这样做,但是:

  • 看起来你在Filename:MyFile & ".docx".
  • 以下是 Document.SaveAs 的有效文件格式:https ://msdn.microsoft.com/EN-US/library/office/ff940508.aspx 。我猜您可能必须保存为 RTF (pbFileRTF = 6) 或 HTML,然后通过 Word 的互操作将其转换为 .docx。诚然,这篇文章已被弃用,也指向了这个方向: https: //support.microsoft.com/en-us/kb/302939。(也许您必须使用数字 6 而不是定义的常量,因为您在 Excel 中执行此操作)

编辑:wdFormatXMLDocument 可能未定义,因为您从 Publisher 运行宏,因此最简单的方法是将其替换为 12

于 2015-09-22T21:45:38.333 回答