Hi. On occasion, I get a program crash when I run this macro to pub a cdr to pdf. I don't what causes it and I lose work sometimes. If anyone can check this code I'd be so grateful.
Sub PublishToPdf() Dim dn As String, ps As PDFVBASettings Set ps = ActiveDocument.PDFSettings If ActiveDocument.Dirty Then ActiveDocument.Save On Error GoTo ErrHandler 'ps.ShowDialog dn = Left$(ActiveDocument.FullFileName, Len(ActiveDocument.FullFileName) - 4) & ".pdf" ActiveDocument.PublishToPdf dn dn = Left$(ActiveDocument.FullFileName, Len(ActiveDocument.FullFileName) - 4) & ".pdf" ExitSub: Exit Sub ErrHandler: MsgBox "Error occured: " & Err.Description & Err.Number Resume ExitSub End Sub
I went through your code, you have a line after "ActiveDocument.PublishToPdf dn" that serves no purpose that I can tell. It shouldn't be an issue but it seems to be completely unnecessary. If you change the active document in mid-performance it might cause the program to crash as stated by NudeFan. If you could provide more information it would definitely help!
I also suspect this line. I avoid in general using 'Active' objects during an entire procedure. I declare a local variable, assign the 'Active' object to it and use it in the following code.
Dim CurDoc As Document
Set CurDoc = ActiveDocument
With CurDoc
...