Log in

View Full Version : Excel 2003 - Compile Error - Invalid Outside Procedure


RC4TXHVAC
Feb 16, 2009, 11:13 AM
Please Help! This is my first attempt at setting up a Macro in Excel 2003 and all I want to do is print out 8 worksheet pages with a macro.

The first message I get says: "Unable to Record" Then I click on "OK" and it records the key strokes anyway! However, when I try to run it, I end up with that Compile Error Message. Thank you in advance for your assistance. Here is the Macro:

Sub PrintALLpgs()
'
' PrintALLpgs Macro
' Macro recorded 2/16/2009 x XXXXX
'
' Keyboard Shortcut: Ctrl+Shift+P
'
Sheets("Cover").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Energy").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Equip").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Repairs").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Major").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("In-House").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Summary").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Notes").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub

JBeaucaire
Feb 16, 2009, 02:00 PM
Are there other pages to this workbook, or does this represent all the sheets in your workbook?

This one line of code would replace all the individual sheets if that is the case:


Sub PrintALLpgs()
'
' PrintALLpgs Macro
' Macro recorded 2/16/2009 x XXXXX
'
' Keyboard Shortcut: Ctrl+Shift+P

ActiveWorkbook.PrintOut Copies:=1, Collate:=True

End Sub

JBeaucaire
Feb 16, 2009, 02:25 PM
Another idea, if you want to be able to flag certain sheets to print and other not to print and have a macro know which is which, this could do it.

First, make sure your PRINT AREA is set on each sheet properly so they will look right. Then in the first cell putside the print area, put a value in a blank cell, lets choose M1.

Then this macro will print every sheet that has any value in cell M1 on it. Change the cell reference if you want to use something else.

Sub PrintFlaggedSheets()
Dim sht As Worksheet

For Each sht In ThisWorkbook.Worksheets
If sht.Range("M1").Value <> "" Then
sht.PrintOut
End If
Next sht

End Sub