发布者VBA保存为图像

时间:2015-04-10 08:05:04

标签: vba ms-publisher

我开发了以下代码,将当前目录中的所有发布者文件保存为图像,但似乎需要很长时间才能完成。此外,我无法找到一种方法来排除运行宏的当前文件。有人有任何想法吗?

 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

1 个答案:

答案 0 :(得分:1)

假设您的代码在所有其他方面都是正确的,这可能会起到作用

If MyFile = ActiveDocument.FullName Then
    GoTo ContinueLoop
End If

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