Vérifier si un fichier pdf est de l'ouvrir et de le fermer

J'utilise ce code pour exporter un fichier pdf à partir d'un document word.

Avant d'exporter j'ai besoin de vérifier d'abord si un fichier avec le même nom est déjà ouvert, et si oui, le fermer puis sur exporter.

J'ai essayé beaucoup de choses mais pas eu de chance.

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
InformationsquelleAutor user3286479 | 2014-09-07