I am trying to write a vba code to print pdf in a specific order. However, if i just shell command the code will run too fast and the printing order will mess up. I saw online that someone recommend using Wscript.shell, since it has waitonreturn which will wait till the job is done before moving on the next vba code line. The problem is that adobe doesn't totally close after the first pdf was print. It close the pdf itself but adobe still keep running. I have to manually close the adobe after each printing so vba can continue with it's code. Is there any way to fix it? I will share my recent code here. I tried application.wait but it is not very stable because some pdf is big and some are small. I also try taskkill /f /im acrord32.exe but sometimes it will kill the next pdf print and unstable as well. I would like to find a stable way to do it. Great Thanks!
VBA Code:
Sub PrintPDF()
Dim DocName As String
Dim adobePath As String
Dim pAth As String
Dim i As Long
Dim wSh As Object
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
Set wSh = VBA.CreateObject("WScript.Shell")
adobePath = """" & "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" & """"
pAth = Cells(4, 8).Value
i = 2
Do While Cells(i, 3) <> ""
DocName = Cells(i, 3).Value
wSh.Run adobePath & " /n /h /t " & """" & pAth & DocName & """", windowStyle, waitOnReturn
'Shell "taskkill /f /im acrord32.exe"
i = i + 1
Loop
End Sub