Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 6th, 2005, 11:46 AM
Authorized User
 
Join Date: Feb 2005
Location: , , Netherlands.
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can an object reference be public?

Hi all,

Look at the following example:

Public Sub set_wrb
Set wrb = ThisWorkbook.Sheets("Sheet1")
End sub

As far as I can see, wrb is only known within the module where it is declared. Even if I declare wrb Public, the object is not known outside the routine set_wrb (Runtime error 424: Object Required).

How can I access wrb outside set_wrb without repeating the Set statement in every routine?

Thanks in advance

-Max
Reply With Quote
  #2 (permalink)  
Old March 6th, 2005, 11:53 AM
Authorized User
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Declare it as a public function, or property

eg.

Code:
Public Property Get Wrb() As Excel.Worksheet
  Set Wrb = ThisWorkbook.Sheets("Sheet1")
End Property
or

Code:
Public Function Wrb() As Excel.Worksheet
  Set Wrb = ThisWorkbook.Sheets("Sheet1")
End Function
Reply With Quote
  #3 (permalink)  
Old March 6th, 2005, 01:22 PM
Authorized User
 
Join Date: Feb 2005
Location: , , Netherlands.
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this works excellent.

thank you
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
object reference not set to instant of an object shahidrasul ASP.NET 2.0 Basics 1 September 5th, 2008 02:01 PM
Object Reference not set to an instance of object srinivas_chakka ASP.NET 1.0 and 1.1 Professional 0 February 8th, 2006 11:56 AM
How to reference Public Variable in Code Gino Liu Access VBA 2 June 18th, 2003 01:42 PM



All times are GMT -4. The time now is 06:00 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.