Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Explain use of function property
My goal is to check for the existence of a worksheet named "Invoice" within
an open workbook. If it exists, then print it. If not, continue with the existing macro which prints another worksheet tab which will always exist. I need to know if I can use a function to test whether the "Invoice" worksheet exists by returning a true or false value, instead of just attempting to select the worksheet and taking a risk of it not existing then writing error handling code. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Explain use of function property
Public Function bExists(s as String)
for each sh in ActiveWorkbook.worksheets if lcase(s) = lcase(sh.name) then bExists = True exit function end if next bExists = False End Function usage If bExists("sheet1") then worksheets("sheet1").Printout else End if -- Regards, Tom Ogilvy "Freddy" wrote: My goal is to check for the existence of a worksheet named "Invoice" within an open workbook. If it exists, then print it. If not, continue with the existing macro which prints another worksheet tab which will always exist. I need to know if I can use a function to test whether the "Invoice" worksheet exists by returning a true or false value, instead of just attempting to select the worksheet and taking a risk of it not existing then writing error handling code. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Explain use of function property
I do not understand how the relationship works between the Public Function
code and the usage portion of your sample code. Can I not use the Function within a sub procedure? If I attempt to run the sub below I get an error which reads: Compile error: Expected End Sub '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''' Sub InvoiceCheck() Public Function bExists(s As String) For Each sh In ActiveWorkbook.Worksheets If LCase(s) = LCase(sh.Name) Then bExists = True Exit Function End If Next bExists = False End Function 'usage If bExists("sheet1") Then Worksheets("sheet1").PrintOut Else End If End Sub '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''' "Tom Ogilvy" wrote: Public Function bExists(s as String) for each sh in ActiveWorkbook.worksheets if lcase(s) = lcase(sh.name) then bExists = True exit function end if next bExists = False End Function usage If bExists("sheet1") then worksheets("sheet1").Printout else End if -- Regards, Tom Ogilvy "Freddy" wrote: My goal is to check for the existence of a worksheet named "Invoice" within an open workbook. If it exists, then print it. If not, continue with the existing macro which prints another worksheet tab which will always exist. I need to know if I can use a function to test whether the "Invoice" worksheet exists by returning a true or false value, instead of just attempting to select the worksheet and taking a risk of it not existing then writing error handling code. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Explain use of function property
Tom, if you're pressed for time, can you direct me to some reference to see
sample code on the use of "Public Function" along with a Sub procedure? "Tom Ogilvy" wrote: Public Function bExists(s as String) for each sh in ActiveWorkbook.worksheets if lcase(s) = lcase(sh.name) then bExists = True exit function end if next bExists = False End Function usage If bExists("sheet1") then worksheets("sheet1").Printout else End if -- Regards, Tom Ogilvy "Freddy" wrote: My goal is to check for the existence of a worksheet named "Invoice" within an open workbook. If it exists, then print it. If not, continue with the existing macro which prints another worksheet tab which will always exist. I need to know if I can use a function to test whether the "Invoice" worksheet exists by returning a true or false value, instead of just attempting to select the worksheet and taking a risk of it not existing then writing error handling code. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Explain use of function property
"Tom Ogilvy" wrote: Public Function bExists(s as String) for each sh in ActiveWorkbook.worksheets if lcase(s) = lcase(sh.name) then bExists = True exit function end if next bExists = False End Function usage If bExists("sheet1") then worksheets("sheet1").Printout else End if -- Regards, Tom Ogilvy "Freddy" wrote: My goal is to check for the existence of a worksheet named "Invoice" within an open workbook. If it exists, then print it. If not, continue with the existing macro which prints another worksheet tab which will always exist. I need to know if I can use a function to test whether the "Invoice" worksheet exists by returning a true or false value, instead of just attempting to select the worksheet and taking a risk of it not existing then writing error handling code. |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Explain use of function property
Sub InvoiceCheck()
'usage If bExists("Invoice") Then Worksheets("Invoice").PrintOut End If End Sub Public Function bExists(s As String) Dim sh as Worksheet For Each sh In ActiveWorkbook.Worksheets If LCase(s) = LCase(sh.Name) Then bExists = True Exit Function End If Next bExists = False End Function -- Regards, Tom Ogilvy "Freddy" wrote in message ... Tom, if you're pressed for time, can you direct me to some reference to see sample code on the use of "Public Function" along with a Sub procedure? "Tom Ogilvy" wrote: Public Function bExists(s as String) for each sh in ActiveWorkbook.worksheets if lcase(s) = lcase(sh.name) then bExists = True exit function end if next bExists = False End Function usage If bExists("sheet1") then worksheets("sheet1").Printout else End if -- Regards, Tom Ogilvy "Freddy" wrote: My goal is to check for the existence of a worksheet named "Invoice" within an open workbook. If it exists, then print it. If not, continue with the existing macro which prints another worksheet tab which will always exist. I need to know if I can use a function to test whether the "Invoice" worksheet exists by returning a true or false value, instead of just attempting to select the worksheet and taking a risk of it not existing then writing error handling code. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Please explain YIELDMAT function | Excel Worksheet Functions | |||
Large function - Please explain | Excel Worksheet Functions | |||
Please explain function/formula | Excel Worksheet Functions | |||
can someone explain function 'ara'? | Excel Worksheet Functions | |||
Function behaviour, can someone explain please? | Excel Programming |