title: Check if a certain pdf file is open and close it
body: <p>I use this code to export a pdf file from a word document.</p>
  
  <p>Before exporting I need to check first if a file with the same name is already open, and if so close it then export.</p>
  
  <p>I tried many things but had no luck.</p>
  
  <pre><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("C:\Current Letter Preview.pdf", "") = True Then '==&gt; If the file is not open, this line opens it
      adbDoc.Close (1) '==&gt; Then close it
  
      If adbDoc Is Nothing Then '==&gt; 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 '==&gt; 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
  </code></pre>