Left over instance of Adobe.

rjtaylor

New Member
Joined
Jan 27, 2004
Messages
36
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
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top