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
But, if you declared CurDoc you must use it...
Set ps = CurDoc.PDFSettings and so on. The idea behind this suggestion was to avoid using of the ActiveDocumet, which is volatile if by mistake you click on another open document and everything is messed up.
got it...I think.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Sub PublishToPdf() Dim dn As String, ps As PDFVBASettings Dim CurDoc As Document Set CurDoc = ActiveDocument Set ps = CurDoc.PDFSettings On Error GoTo ErrHandler dn = Left$(ActiveDocument.FullFileName, Len(ActiveDocument.FullFileName) - 4) & ".pdf" CurDoc.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
Not really!
Update also line 7 and 9 (which is most likely the bad guy )
Haha. I'm still learning.
Now I got it. we good. thanks for your help.
Did you try this PDF export manually?
Does it work with your PDF default export settings?
Did the code in discussion work after making this modification?
A little feedback will not kill anybody...