I have a sub that prints out each PDF in a folder. The first instance of Adobe remains open. all other instances will close once the shell command has finished. How do I close that first instance. Here is the code.
VBA Code:
Private Sub Print_PDF(sPDFfile As String)
Dim ShellCommand As String
Shell "C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe /n /s /o /h /t " & Chr(34) & sPDFfile & Chr(34), vbNormalFocus 'vbMinimizedNoFocus ' vbNormalFocus
Application.Wait (Now + TimeValue("00:00:01"))
End Sub
Public Sub Print_All_PDF_Files_in_Folder_new()
'make sure no left over files in default location
Dim Counter As Integer, i As Integer
Counter = 0
i = 1
On Error Resume Next
Kill PrinterPath & "CFD_Casefiles.pdf"
On Error GoTo 0
Dim folder As String
Dim PDFfilename As String
setVarables
folder = DirLocation & "PDFtoFlatten\"
If Right(folder, 1) <> "\" Then folder = folder & "\"
PDFfilename = Dir(folder & "*.pdf", vbNormal)
While Len(PDFfilename) <> 0
Main.lblstatusStart.Caption = "Flattening " & i & " of " & PDFcount
Main.lblStatus.Caption = PDFfilename
DoEvents
Print_PDF folder & PDFfilename
On Error Resume Next
Do
DoEvents
Sleep 300
Err.Clear
FileCopy PrinterPath & "CFD_Casefiles.pdf", folder & "Flattened\" & PDFfilename
If Err Then
Else
Kill PrinterPath & "CFD_Casefiles.pdf"
i = i + 1
End If
Sleep 200
Loop Until Err.Number = 0
On Error GoTo 0
PDFfilename = Dir() ' Get next matching file
Wend
End Sub