|
-
Oct 26th, 2005, 02:35 PM
#1
Thread Starter
Frenzied Member
EXCEL: How To: Pass Workbook Handle to Sub [RESOLVED - duh]
Esteemed Forum Participants and Lurkers:
===============================
Excel 2003 VBA
I must be doing something dumb here ... I can't seem to pass a workbook reference to a Subroutine ...
Code:
Sub aTest()
Dim aBook As Workbook
Set aBook = ActiveWorkbook 'Set a handle to a WorkBook
Debug.Print aBook.Name 'Prove that we can access by handle
Pass_Book (aBook) '<< THIS FAILS
End Sub
Sub Pass_Book(TestBook As Workbook)
Debug.Print TestBook.Name, TestBook.Sheets(1).Name
End Sub
I get an error when I call "Pass_Book":
Run-time error '438': Object doesn't support this property or method
Thank you for any and all comments, suggestions, and assistance.
Last edited by Webtest; Oct 26th, 2005 at 03:13 PM.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Oct 26th, 2005, 03:03 PM
#2
Re: EXCEL: How To: Pass Workbook Handle to Sub ???
Take the parenthesis off
VB Code:
Sub aTest()
Dim aBook As Workbook
Set aBook = ActiveWorkbook 'Set a reference to a WorkBook
Debug.Print aBook.Name 'Prove that we can access by reference
Pass_Book aBook '<< THIS WORKS NOW
End Sub
Sub Pass_Book(TestBook As Workbook)
Debug.Print TestBook.Name, TestBook.Sheets(1).Name
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 26th, 2005, 03:07 PM
#3
Thread Starter
Frenzied Member
Re: EXCEL: How To: Pass Workbook Handle to Sub ???
Why in the crappy blazes do the "Hint" popups ALWAYS show parentheses whether they should be there or not? I'll never learn!
Thanks RobDog.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Oct 26th, 2005, 03:16 PM
#4
Re: EXCEL: How To: Pass Workbook Handle to Sub [RESOLVED - duh]
You only need the parenthesis when you are calling a sub in this method..
This is old style code, and I very much doubt that people still use it, it is however required if you are interested in a return value of a function, for example to return the button that was pressed on a MsgBox Function, or another way of looking at this is to say..
VB Code:
varName = FunctionName(Parameters)
If you weren't interested in the returned value you would just call the function like so..
But this type of function call is a waste of memory, and if you were to use nothing but non-return calls to functions throughout your code then you would be better off setting these as Sub procedures instead, but that's another argument I don't want to kick off on this forum..
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|