For Each loop function not working properly

kiraexiled

New Member
Joined
Sep 1, 2012
Messages
3
Hi everyone, I'm working on a macro that loops through a column of values and prints pdfs based on those variables.

I have managed to get everything working fine except for the order of the print.

Below is my macro:

Code:
Sub DocPrint()

    Worksheets("Main").Activate
    Application.ScreenUpdating = False
    ActiveCell.CurrentRegion.Select
    
    On Error Resume Next
        
    For Each a In Range("E21")
        If a.Value = "" Then Exit Sub
    File = "*" & a.Value & "*"
    fNAME = fPATH & "*" & File & "*" & ".pdf"
    Shell "C:\LOCALAPP\Apps\AcrobatReader\Reader\AcroRd32.exe /p /h " & fNAME
    
    Application.Wait Now + TimeValue("00:00:10")

    Next a
End Sub

I have values from E21 to E30. The macro would first print a pdf based on the value in E21 and right after that starts printing based on values from E30 then E29, E28,E27 and so on. What have I done wrong to make the macro loop in a reverse order?

Also the application wait function doesnt seem to be working either. Would appreciate help on that too.

Thanks a bunch!

Sam.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi,I've tried that previously but the results are the same. I've also tried the code with

Code:
For Each a In Range("E21",Range("E21").End(xlDown))

No luck with that too. Any idea why this is happening?

-

Ok i've found the culprit behind this. Company updated adobe and now the print buffer time is much longer. All i had to do was set the wait time to 14 secs. Thanks hh!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,203,606
Messages
6,056,278
Members
444,854
Latest member
goethe168

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