Chip,
I am having a problem get something to print. This is my first time creating
a function, so I've made some errors. Could you look at this code and set me
on the right track?
Function SheetExists(SName As String) As Boolean
On Error Resume Next
End Function
Private Sub CommandButton3_Click()
'***** PRINT ALL BUTTON *****
'***** Print the Cover Tab *****
If SheetExists("Cover") = True Then
Sheets("Cover").Select
'ActiveSheet.PageSetup.PrintArea = "$A$1:$M$28"
'ActiveSheet.PageSetup.LeftMargin =
Application.InchesToPoints(0.25)
'ActiveSheet.PageSetup.RightMargin =
Application.InchesToPoints(0.25)
'ActiveSheet.PageSetup.CenterHorizontally = True
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If
' Sheets("Index").Select
' Range("A1").Select
'***** Print the Index Tab *****
If SheetExists("Index") = True Then
Sheets("Index").Select
'ActiveSheet.PageSetup.PrintArea = "$D$1:$R$38"
'ActiveSheet.PageSetup.LeftMargin =
Application.InchesToPoints(0.25)
'ActiveSheet.PageSetup.RightMargin =
Application.InchesToPoints(0.25)
'ActiveSheet.PageSetup.CenterHorizontally = True
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If
' Sheets("Index").Select
' Range("A1").Select
'***** Print the Balance Sheet Tab *****
If SheetExists("BS") = True Then
Sheets("BS").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If
' Sheets("Index").Select
' Range("A1").Select
'***** Print the Cash Position Tab *****
If SheetExists("CashPosition") = True Then
Sheets("CashPosition").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If
What did I mess up? I really appreciate your help!!
"Chip Pearson" wrote:
Use a function like
Function SheetExists(SheetName As String, Optional WB As
Workbook) As Boolean
On Error Resume Next
SheetExists = CBool(Len(IIf(WB Is Nothing, ThisWorkbook, WB)
_
.Worksheets(SheetName).Name))
End Function
Then call it with code like
If SheetExists("Sheet3",ThisWorkbook) = True Then
' sheet exists
Else
' sheet does not exist
End If
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
"dajns" wrote in message
...
I have 200 workbooks that are 80% the same. One worksheet in
each is an index
that has checkboxes for printing. I need to verify the presence
of the sheet
to print before I issue the print command. Any sugguestions?