Tornado1981
Board Regular
- Joined
- Apr 1, 2010
- Messages
- 248
Hi,
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.
Any Suggestions would be really appreciated.
Thank u in advance.
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.
Any Suggestions would be really appreciated.
Thank u in advance.
Code:
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(FilePath & "Current Letter Preview.pdf", "") = True Then '==> Here if the file is not open, it opens it.
adbDoc.Close (1)
If adbDoc Is Nothing Then '==> Here it need to check if any pdf files are open, but it doesn't work.
adbApp.Exit
End If
Set adbApp = Nothing
End If
Dim wordApp As Word.Application
Dim wordDoc As Word.Document
If IsFileOpen(FilePath & "TemporaryLetter.docx") Then
Set wordApp = GetObject(, "Word.Application")
wordApp.Documents(FilePath & "TemporaryLetter.docx").Close
Else
Set wordApp = CreateObject("Word.Application")
With wordApp
.Visible = True
.WindowState = 2
End With
End If
Set wordDoc = wordApp.Documents.Open(FilePath & "TemporaryLetter.docx")
wordDoc.ExportAsFixedFormat OutputFileName:=FilePath & "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(FilePath & "Current Letter Preview.pdf", "")
adbDoc.BringToFront
Set adbPageView = adbDoc.GetAVPageView()
Call adbPageView.ZoomTo(0, 100)
Set adbDoc = Nothing
Set adbPageView = Nothing