OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   Waiting for Export to finish before continuing (http://forum.oberonplace.com/showthread.php?t=24695)

nic 15-09-2014 03:24

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)

...do something

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

end sub

All times are GMT -5. The time now is 19:52.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com