Mass printing PDF files

Asator

Board Regular
Joined
Apr 5, 2010
Messages
186
Has anyone had any problems mass printing PDF files with acrobat using VBA? My code seems to work most of the time, but randomly it just doesn't print the file. This is for outlook, but that really shouldn't matter for this part of the code. The files get saved to the correct location according to the rule 100% of the time. Printing seems to only work like 80-90% of the time for PDF files. There isn't any error, it juts doesn't print. I added the sleep (2 seconds) and Do Until loops to try and make sure Shell is returning a valid process id, but it doesn't seem to work.

Code:
            For k = Len(olAtts(j)) To 1 Step -1
                If Mid(olAtts(j), k, 1) = "." And extfound = False Then
                    'extension determined, go with it
                    AttName = Left(olAtts(j), k - 1)
                    AttExt = Right(olAtts(j), Len(olAtts(j)) - k + 1)
                    extfound = True
                End If
            Next k
            'set file name structure
            AttFileSavename = AttName & "_" & Format(objMsg.SentOn, "hh.mm.ss") & AttExt
            
            olAtts(j).SaveAsFile rtFolder & sender_folder & "\" & dStr & "\" & AttFileSavename
            
            
            Select Case LCase(AttExt)
                Case ".jpg", ".gif", ".png", ".bmp"
                    'do nothing
                Case ".pdf"
                    
                    If prFlag = True Then
                        RetVal = Null
                        
                        Do Until IsNumeric(RetVal) And RetVal <> 0
                            Call Sleep(pDelay)
                            DoEvents
                            
                            RetVal = Shell(AcroPath & "AcroRd32.exe /t /h " & Chr(34) & rtFolder & sender_folder & "\" & dStr & "\" & AttFileSavename & Chr(34))
                            'Print using acrobat reader, since for some reason we don't have the shell extension
                        Loop
                    End If
                Case Else
                    If prFlag = True Then
                        RetVal = Null
                        Do Until RetVal = 2 Or RetVal = 31 Or RetVal > 32
                        
                            Call Sleep(pDelay)
                            DoEvents
                        
                            RetVal = ShellExecute(0, "print", rtFolder & sender_folder & "\" & dStr & "\" & AttFileSavename, "", "", 1)
                            'Print using shell extension
                        Loop
                    End If
            End Select

Any ideas? (Yes i know this is the excel forum, but you guys don't have an Outlook forum :p)
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,224,505
Messages
6,179,151
Members
452,891
Latest member
JUSTOUTOFMYREACH

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