Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please explain YIELDMAT function JoeU2004 Excel Worksheet Functions 9 September 10th 09 02:04 AM
Large function - Please explain Danny Excel Worksheet Functions 5 December 18th 07 08:34 PM
Please explain function/formula Tara H Excel Worksheet Functions 6 July 24th 06 07:16 PM
can someone explain function 'ara'? feachmarsin Excel Worksheet Functions 1 April 20th 06 01:26 AM
Function behaviour, can someone explain please? Ron[_28_] Excel Programming 2 February 8th 05 03:49 PM


All times are GMT +1. The time now is 11:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"