出版商 VBA 另存为图片

Publisher VBA to save as image

我已经开发了以下代码来将当前目录中的所有发布者文件保存为图像,但是 运行 似乎需要很长时间。另外,我想不出一种方法来排除宏 运行ning 来自的当前文件。有人有什么想法吗?

 Sub Looptest()

      Dim MyFile As String, Sep As String
      Dim objPub As Object
      Set objPub = CreateObject("Publisher.Application")
      Dim folder As String
      folder = CurDir()
    If Len(Dir(folder & "\" & "jpg", vbDirectory)) = 0 Then
        MkDir (folder & "\" & "jpg")
    End If


       Sep = Application.PathSeparator

      If Sep = "\" Then
         ' Windows platform search syntax.
         MyFile = Dir(CurDir() & Sep & "*.pub")

      Else

          MyFile = Dir("", MacID("XLS5"))
      End If

      ' Starts the loop, which will continue until there are no more files
      ' found.


      Do While MyFile <> ""
    'If MyFile = "macro.pub" Then
    'GoTo ContinueLoop
    'End If

    Dim pubApp As Publisher.Application
    Dim pubDoc As Publisher.Document
    Dim folder2 As String
    folder2 = CurDir() & Sep & MyFile


    Set pubApp = New Publisher.Application

    pubApp.Open folder2
    'pubApp.ActiveWindow.Visible = True
    num = folder2
    pubApp.ActiveDocument.Pages(1).SaveAsPicture CurDir() & Sep & "jpg" & "\" & MyFile & ".jpg"
    pubApp.Quit
             MyFile = Dir()
    'ContinueLoop:
          Loop

       End Sub

我已经注释掉了我尝试跳过该文件(在本例中称为 Macro.pub),因为它似乎停滞不前。

如有任何帮助,我们将不胜感激!

-Cr1kk0

假设您的代码在所有其他方面都是正确的,这可能会成功

If MyFile = ActiveDocument.FullName Then
    GoTo ContinueLoop
End If

我猜你的检查失败了,因为你在比较短文件名和完整文件名。 (您也可以将整个路径硬编码为 macro.pub)