View Single Post
Old 15-09-2014, 03:24
nic nic is offline
Join Date: May 2009
Posts: 90
Default Waiting for Export to finish before continuing

Im trying to loop through a series of files exporting them as pdf's and png's. Had a look at wOxxOm's macro which would seem to do exactly what Im after but on Draw 7 it crashes the application - I think this is related to the files not being fully saved before the next is opened.

I couldn't debug the issue so wrote a loop that takes the file names from Excel and encountered the same problem, pausing the macro between loops seems to allow it to work and wonder if someone might help me to get the loops to wait for the last loop to finish before starting the next.

Below is the main code from wOxxOm's macro which I would prefer to get working and beneath that my hash.


Sub psdExport()
   Dim file$, expflt As ExportFilter, doc As Document, errs$, report$
   Static folder$: If folder = "" Then folder = "H:\test 1"
   folder = Application.CorelScriptTools.GetFolder(folder, "Initial folder: " + folder, AppWindow.Handle)
   If folder = "" Then Exit Sub
   If right(folder, 1) <> "\" Then folder = folder + "\"
   On Error GoTo ErrHandler
   Application.PanoseMatching = cdrPanosePrompt ' may change to cdrPanoseTemporary
   file = Dir(folder + "*.cdr")
   Do While file <> ""
      Set doc = Application.OpenDocument(folder + file)
      If Not doc Is Nothing Then

... do something         

      file = Dir
   MsgBox report + vbNewLine + "--------------" + vbNewLine + errs, , _
      "Processed folder: " + folder
   Exit Sub
   errs = errs + "Error on " + file + ": " + ERR.Description + vbNewLine
   Resume NextFile
End Sub
sub excelloop
Dim n As Long
Dim crlfile As String
Dim fullpath As String

Set xl = GetObject(, "Excel.Application")

For n = 1 To 5

crlfile = xl.cells(n, 1).Value
fullpath = "d:\Users\Nic\Desktop\drawfiles\" & crlfile & ".cdr"
Application.OpenDocument (fullpath) something

ActiveDocument.PublishToPDF "d:\Users\user\Desktop\pdfs\" & crlfile & ".pdf"
next n

end sub

Last edited by nic; 15-09-2014 at 03:28.
Reply With Quote