Problem With Macro To Print PDFs

July 28, 2011 at 06:53:55
Specs: Windows XP

please say me what is the problems of following Code
Dim sAdobeReader As String
Dim sStrPDFFileName As String
Dim sss As String

sAdobeReader = "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.EXE"
sStrPDFFileName = Range("C6")

For s = 6 To 205

If (Range("B" & s) <> "") Then
sss = sStrPDFFileName & Range("B" & s) & ".pdf"
Dim retval
retval = Shell(sAdobeReader & " " & sss, 3)
Application.SendKeys "^p~" , False
Application.SendKeys "%{F4}", True
Range("B" & s).Columns.Interior.ColorIndex = 33
MsgBox Range("B" & s).Value & " " & "Is Printed"
End If

Next s
Column B is list of my pdf
and Range("C6") is the address of map on my hard disk
but after Run this code sum pdf is not print
by thanks

See More: Problem With Macro To Print PDFs

July 28, 2011 at 07:47:40
re: "but after Run this code sum pdf is not print"

I assume that you mean some, but not all, of your PDF's are being printed. Are random PDF's not being printed? Does it stop printing after a certain row? A little more detail about what is happening might help us help you.

Try this:

Place your cursor within the code in the VBA Editor and press F8 to single step through the code. If the problem goes away, it might be due to the SendKeys function.

SendKeys is well known to be finicky because so much system related stuff can get in the way of the processing of the SendKeys commands.

You might need to add some wait loops or something in the code to allow the files to open and then print.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

Report •

July 28, 2011 at 08:27:29
excuse me i mean " Some " and that was a Typing error
how can add wait loop in my code? i try "Message Box", But this is not The usual method and return error again in some case .
i think that my answer is in the following line . (true & false - wait or not wait)
Application.SendKeys "^p~" , False
Application.SendKeys "%{F4}", True
As i test my code in once and without loop it work Properly

Report •

July 28, 2011 at 10:48:57
re: "and return error again in some case "

You didn't say anything about an error in your first post.

When you ask for assistance in a Help forum, you should always include any errors that you are getting. We can't see your computer from where we're sitting, so we can only go by what we read in your post.

When you say that some of your PDFs are not printing, the only assumption we can make is that they are simply not printing. If you don't tell us that the code is producing an error, how would we know to address that issue?

What error are you getting and on which line does it occur?

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

Report •

Related Solutions

July 28, 2011 at 22:27:16

I send you my complete code
You can try it on your computer
but You're just a long discussion
Goodbye forever

Report •

July 29, 2011 at 18:43:19
There would be no sense in trying your code unless my spreadsheet was set up exactly like yours, with a cell to mapped drive location full of PDF's and a list of PDF's laid out and formatted exactly like yours.

You asked for our help, which is offered on a free and voluntary basis. It's not our job to spend time trying to replicate your situation by guessing what your spreadsheet looks like and hoping we get it right. I'm not going to create a folder full of PDF's and set up a spreadsheet with a list of file names just to test your code.

If you don't wish to share the error that your code is producing, so be it.

Good luck with your project.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

Report •

Ask Question