PDA

View Full Version : Solved: File Print Macro



shickles
08-12-2004, 07:01 AM
I would like to be able to print 25 excel files in a certain order:

gvyield
gvopstcp
gvefscon
gvfrprod
gvprosum - *needs to be in portrait*
gvpaws
gvgibhar
gvadcostcp
gvbonewhbb
gvdebnew
gvbonedk
gvplgen
gvwaste
gvrepmai
gvadmin
gvcstfp
gvfdmill
gvfdhaul
gvtruck
gvospur
gvfdmill trucking
gvqa
gvmaint
gvpurch
gvsanit

If I could put the macro in the gvsanit file and when I am done editing it I could use some keystroke and it would print those files in order that would be great. Thanks in advance.

Steve

Steiner
08-12-2004, 07:45 AM
I'd arrange the workbooks to be printed in an Excel table. For that example, name you need 2 columns: name of the workbook, orientation (1 = portrait, 2 = landscape). Now name the first name cell "rngPrint" and try the following macro (don't forget to change sPath!):



Sub PrintAll()
Dim iRow%, iCol%, Wb As Workbook, MainWs As Worksheet, sPath$, Ws As Worksheet

sPath = "E:\test\" 'Adjust to your path!!

Set MainWs = ActiveWorkbook.Worksheets(1)
iRow = MainWs.Range("rngPrint").Row
iCol = MainWs.Range("rngPrint").Column

Do Until MainWs.Cells(iRow, iCol).Value = ""
Set Wb = Application.Workbooks.Open(sPath & MainWs.Cells(iRow, iCol).Value)
For Each Ws In Wb.Worksheets
Ws.PageSetup.Orientation = MainWs.Cells(iRow, iCol + 1).Value
Ws.PrintOut
Next Ws
Wb.Close False
iRow = iRow + 1
Loop
End Sub

Daniel

shickles
08-12-2004, 09:11 AM
OKay... when I tired this I get a 400 error code.

I made a new workbook, enter all the file names in column A, in column B I put 1 or 2. I named cell A2 "rngPrint"

Am I missing something?

geekgirlau
08-12-2004, 09:46 PM
First, check that your path is okay, and has "\" at the end.

If you are still receiving the error, try stepping through the code. Minimise every application that you have running, then display the workbook with the filenames and the code. In a blank spot on your Taskbar (at the bottom of the screen) click the right mouse button and select Tile Windows Horizontally. Now click in the code and press F8 to step through one line at a time. This will highlight the line that is causing the problem.

Steiner
08-13-2004, 12:35 AM
Geekgirlau is completely right.
And it would sure be helpful to see where the error appears, because the error message is not too meaningful.

shickles
08-13-2004, 04:58 AM
Thanks for your help. I did not have the "\" . Thanks again....