打开文件夹中的Publisher文件并另存为Word文档

时间:2014-10-20 12:52:03

标签: excel vba excel-vba ms-word ms-publisher

我需要打开当前保存在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

我似乎无法超越这一点。

1 个答案:

答案 0 :(得分:0)

不确定为什么要在Excel中执行此操作,但是:

编辑: 因为你从Publisher运行宏,所以可能没有定义wdFormatXMLDocument,所以最简单的方法是将它替换为12