I use this code to export a pdf file from a word document.
Before exporting I need to check first if a file with the same name is already open, and if so close it then export.
I tried many things but had no luck.
Dim adbApp As Acrobat.AcroApp
Dim adbDoc As Acrobat.AcroAVDoc
Dim adbPageView As Acrobat.AcroAVPageView
Set adbApp = CreateObject("AcroExch.App")
Set adbDoc = CreateObject("AcroExch.AVDoc")
If adbDoc.Open("C:\Current Letter Preview.pdf", "") = True Then '==> If the file is not open, this line opens it
adbDoc.Close (1) '==> Then close it
If adbDoc Is Nothing Then '==> Doesn't understand that I want to check if any pdf files are open
adbApp.Exit
End If
Set adbApp = Nothing
End If
Dim wordApp As Word.Application
Dim wordDoc As Word.Document
If IsFileOpen("C:\TemporaryLetter.docx") Then
Set wordApp = GetObject(, "Word.Application")
wordApp.Documents("C:\TemporaryLetter.docx").Close '==> Is there something like that regarding acrobat IAC?
Else
Set wordApp = CreateObject("Word.Application")
With wordApp
.Visible = True
.WindowState = 2
End With
End If
Set wordDoc = wordApp.Documents.Open("C:\TemporaryLetter.docx")
wordDoc.ExportAsFixedFormat OutputFileName:="C:\Current Letter Preview.pdf", _
ExportFormat:=wdExportFormatPDF
wordDoc.Close savechanges:=wdDoNotSaveChanges
Set wordDoc = Nothing
If wordDoc Is Nothing Then
wordApp.Quit
End If
Set wordApp = Nothing
Call adbDoc.Open("C:\Current Letter Preview.pdf", "")
adbDoc.BringToFront
Set adbPageView = adbDoc.GetAVPageView()
Call adbPageView.ZoomTo(0, 100)
Set adbDoc = Nothing
Set adbPageView = Nothing