Message 1 of 4
Macro PDF failed when PDF file is already open.

Not applicable
09-17-2013
02:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I created a macro for generate a PDF drawing, but when one file has been already created, AND he's already open, the macro don't work.
How to stop the macro automatically and notify that the macro has been stopped because the file is open.
Below, the current macro :
Sub PublishPDF() 'Get the PDF translator Add-In. Dim PDFAddin As TranslatorAddIn Set PDFAddin = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") 'Set a reference to the active document (the document to be published). Dim oDocument As Document Set oDocument = ThisApplication.ActiveDocument Dim oContext As TranslationContext Set oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = kFileBrowseIOMechanism 'Create a NameValueMap object. Dim oOptions As NameValueMap Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap 'Create a DataMedium object. Dim oDataMedium As DataMedium Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium 'Check whether the translator has 'SaveCopyAs' options. If PDFAddin.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then If TypeOf oDocument Is DrawingDocument Then oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Sheet_Range") = kPrintAllSheets oOptions.Value("Remove_Line_Weights") = 0 oOptions.Value("Remove_Line_Weights") = 0 oOptions.Value("Vector_Resolution") = 400 End If End If 'Set filename as original document filename. Dim FileName As String FileName = Left(oDocument.DisplayName, Len(oDocument.DisplayName) - 4) 'Set the destination to save files. oDataMedium.FileName = "C:\...\" & FileName & ".pdf" 'Publish document. Call PDFAddin.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) End Sub