Results 1 to 7 of 7
  1. #1
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reference Activecell in class module (2000 sp-3/ 98SE/ VB6)

    I'm needing a way of grabbing a reference to the activecell in a workbook, for a class method in an ActiveX DLL. From VBA it's as simple as using ActiveCell.Row etc. I've been trying to to substitute Application.Caller and trying also to find a way to retrieve a reference to "Application" as a static member with class-wide scope. No luck so far though... I'm in uncharted VB territory now, I'm afraid. Any suggestions please?

    Alan

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Reference Activecell in class module (2000 sp-3/ 98SE/ VB6)

    Alan,
    Hard to say without knowing the specifics, but can't you write your method to accept a Workbook (or Application) object as a parameter? You can then reference from that object as necessary.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reference Activecell in class module (2000 sp-3/ 98SE/ VB6)

    Hi Rory

    I already have a reference to the particular workbook, but still couldn't get my hooks into the ActiveCell from within the object. I have now gone back to a redesign, in which I don't instantiate the object until the appropriate range/ cell has been selected by the user. This makes it easy to pass a (static) reference to the ActiveCell to the initialization routine, and glean all the required info from there.

    Even though that's "problem solved" for this particular class, I'd still like to find out if it's at all possible to do what I was originally thinking i.e. reference the ActiveCell or Selection directly from within an object.

    cheers
    Alan

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Reference Activecell in class module (2000 sp-3/ 98SE/ VB6)

    Alan,
    Sorry, I should have been clearer - for ActiveCell specifically, you would need to pass an Application object to the method. You could also create a separate routine to initialise a private variable in your class so you can use it in any method.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reference Activecell in class module (2000 sp-3/ 98SE/ VB6)

    Yep <img src=/S/yep.gif border=0 alt=yep width=15 height=15> I realized you probably meant a reference to Application (which "owns" ActiveCell). Does "Application" need any qualification when referenced? I'm guessing it's just a matter of something as simple as:

    Dim ap As Application
    Set ap = Application
    ' ...Object.InitRoutine(args..., ap, ...args) -> ap.Name="Microsoft Excel"

    Alan

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Reference Activecell in class module (2000 sp-3/ 98SE/ VB6)

    or just:
    Object.InitRoutine(args..., application, ...args)
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reference Activecell in class module (2000 sp-3/ 98SE/ VB6)

    Easier still <img src=/S/smile.gif border=0 alt=smile width=15 height=15>. Thanks Rory.

    Alan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •