View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
ker_01 ker_01 is offline
external usenet poster
 
Posts: 395
Default Passing sheet (using codename) to separate sub as optional par

Interesting, "Call" is only needed if I put the parameters in parenthesis? It
works, but I don't comprehend the relationship (or reasons when to use) Call
vs the parens.

But I'd listen to Bob, too.


I always do :) ...and to you and the other experts in this forum too- I've
never had a formal class in VBA, but it is amazing how much I can do just
based on what I've learned here (and hours of hitting my head on my keyboard
while trying random syntax ;-)

Best,
Keith

"Dave Peterson" wrote:

Drop the ()'s in your procedu

Sub ALoad_FinRTs()
ShowAllSheets Sheet15
'do stuff
End Sub

Or add the Call keyword:

Sub ALoad_FinRTs()
Call ShowAllSheets(Sheet15)
'do stuff
End Sub

But I'd listen to Bob, too.


ker_01 wrote:

I have a large, convoluted workbook. With some of my subs that bring in raw
data from other files, I want to unhide the sheet where that data is pasted
just so I can review it (without unhiding all sheets). There are also some
subs where I want to unhide every worksheet in the workbook.

So, I wrote a sub that I thought would handle both, but I'm getting errors
when I try to call it, and it also fails when I place the cursor inside the
sub and try to run it directly.

Sub ShowAllSheets(Optional IndSht As Worksheet)
Dim sht As Worksheet
'name<codename, but irrelevant -just determines if a sheet was passed to
the sub
If (IndSht.Name) < "" Then
IndSht.Visible = xlSheetVisible
Else
For Each sht In Excel.ActiveWorkbook.Worksheets
sht.Visible = xlSheetVisible
Next
End If
End Sub

When I try to run the code above, it pops up a dialogue box with a list of
macros to run, rather than just running this one as I would have expected.

Also, when I try to call the sub (below) I get a run time error 438, object
doesn't support this property or method

Sub ALoad_FinRTs()
ShowAllSheets (Sheet15)
'do stuff
End Sub

I think I have more than one problem here, but I'm not sure what the problem
is, so I can't experiment with solutions...

Thanks!
Keith


--

Dave Peterson
.