Results 1 to 15 of 15
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA project explorer currently selected item (VBA/Excel/2000/SP3)

    Does anyone know how to return the currently selected module in the project explorer?

    I have managed to succesfully find out the name of the selected module by interrogating the context menu ("Project Window" commandbar) and parsing the 'Remove <item>' button, but the problem is that I don't know which project it is in. This is a problem because you can havemodules of the same name in 2 or more seperate projects, so I don't know which is the correct one.

    I suspect the only way to do this is to grab the hwnd of the project window and throw it into some API calls which will interrogate the Treeview control used in the project explorer. If anyone is familiar with doing this via the API I'd really appreciate a few pointers.

    Many thanks,

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VBA project explorer currently selected item (VBA/Excel/2000/SP3)

    I'm sorry that you haven't got an answer yet to this post and to your other recent question in this forum. I'm afraid it is a bit removed from the focus of the Lounge - my impression is that many Loungers have experience in customizing the Office apps using VBA, but not in customizing the Visual Basic Editor. Still, let's hope that someone has an idea, just don't get your hopes up...

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA project explorer currently selected item (VBA/Excel/2000/SP3)

    Fair point. This isn't very typical stuff! What I'm doing is writing a code management add-in for developers (primarily for myself!).

    If I can't figure out a way to do this stuff then I'll forget about the context menu. Shame, but it's not essential to the app.

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA project explorer currently selected item (VBA/Excel/2000/SP3)

    Since you seem to have managed to get the module's name, this may help:

    Application.VBE.ActiveVBProject
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA project explorer currently selected item (VBA/Excel/2000/SP3)

    The problem is that the module which I select in the project window may not be contained in the active project.

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA project explorer currently selected item (VBA/Excel/2000/SP3)

    So what is the point then, once a module is opened it is both highlighted and its project is the active project, right?

    Sounds like you want to capture a rightclick (which selects the module's entry in the explorer, but does not activate it, nor change the active project) in the project explorer to show a custom menu and do something, am I right?
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  7. #7
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA project explorer currently selected item (VBA/Excel/2000/SP3)

    It is possible to select an item in the project explorer without activating that module or it's parent project.

    You are right, I want to customise the project explorer context menu according to which item is selected. The active module/project are completely irrelevant.

    At this point this and the other thread have probably merged.

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA project explorer currently selected item (VBA/Excel/2000/SP3)

    <hr>It is possible to select an item in the project explorer without activating that module or it's parent project.<hr>
    I guess you were right in the first post, that would require using the API (not sure if you can do that though).

    <hr>You are right, I want to customise the project explorer context menu according to which item is selected. The active module/project are completely irrelevant.
    <hr>
    I guess the only way I would know how to do that is build your own form that captures all components in the VBE and shows them there. Maybe using a treeview control. Then change some controls on the userform depending on what component is selected.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  9. #9
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA project explorer currently selected item (VBA/Excel/2000/SP3)

    The form you're talking about is exactly what I have as the main interface for the add-in. It lists all the projects and components in a Treeview as you suggest and everything can be done from there. The currently selected component in the project explorer is irrelevant when this form is shown.

    The extension of the project explorer context menu is just another GUI feature which I'd like to have. It's not absolutely essential, so I'm not sure if I want to spend too much time on it, but I might have a quick look at the websites you mentioned here to see if there is anything which can help.

    Thanks for the help,

  10. #10
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VBA project explorer currently selected item (VBA/Excel/2000/SP3)

    Have you looked at MZ-Tools? It provides some tools for organizing your projects into folders, plus some very handy utilities for working in the VBE, and it works in VB as well as VBA. I find it invaluable.
    Charlotte

  11. #11
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA project explorer currently selected item (VBA/Excel/2000/SP3)

    Hi Charlotte,

    I was going to suggest that one, because it does know what item is selected in the project explorer! (try rightclicking it ans choosing statistics, it will show the stats of the currently selected item). Maybe the creator of mz-tools is willing to share the technique he used to accomplish this.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  12. #12
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA project explorer currently selected item (VBA/Excel/2000/SP3)

    The site seems to be down at the moment, but I'll take a look later. As Jan says, if the creator is willing to share the technique that would be great!

    Thanks,

  13. #13
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: VBA project explorer currently selected item (

    I wouldn't count on obtaining the source code for MZ-Tools, if that is what you're looking for. From the site:

    MZ-Tools FAQ

    <hr>Is the add-in source code available?

    No, the source code is not available. However, I try to implement every request I receive in the following version and I release fixes as soon as the bugs are detected and corrected.

    For those of you who want the source code for learning purposes, I think that the best way to learn is to develop your own add-in, which is the route I followed. You can post specific questions in the Microsoft newsgroups and surely you will get the answers.<hr>
    Of course you can always contact the program's creator (email link is on web site) & try to persuade him to divulge some of his secrets. Some add-in authors will provide the source code if you purchase a "registered" copy of the add-in (such as John Walkenbach's Power Utility Pak (PUP) Excel add-in). However, that does not appear to be an option with MZ-Tools. Its author will probably gladly direct you to this page:

    Donations Welcome

    HTH

  14. #14
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: VBA project explorer currently selected item (

    HINT: If you look at the Import table for the .DLL installed with MZ-Tools (MZTools3VBA.dll) you will see a long list of functions imported from MSVBVM60.DLL, described as "Visual Basic Virtual Machine", version 6.0.92.37, on the Properties dialog (I'm using Office 2K on WIN XP system). Many of these functions are referenced only by their ordinal number, which implies that it's up to you to figure out how to use them (see attached pic). Calling functions from external DLL's can be tricky, even where copious documentation is available, such as with the Windows API. Don't know how much documentation is available for the socalled "VB Virtual Machine" DLL, but the fact that many of the functions listed only have an ordinal number, not a name, is not a good sign.... but at least it's a starting point. I would speculate that some of the functionality you see in MZ-Tools is provided by this DLL - the limited functionality provided by the Microsoft Visual Basic for Applications Extensibility 5.3 (VBIDE) library (VBE6EXT.OLB) is likely not sufficient for this purpose. (PS - this is speculation on my part, it's possible the VBVM is used only for the MZ Tools user interface - documentation appears to be sparse....)

    HTH

  15. #15
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA project explorer currently selected item (

    The VB virtual machine is a middle tier which sits between VB 'compiled code' and the windows API. VB uses the VB virtual machine to do nuts and bolts calls to the basic windows plumbing. This won't help in any way in what I'm trying to acheive.

    I'm 99% sure that the way I have to go about solving this problem is to delve into the WinAPI itself and locate the right functions to capture and interrogate the treeview control used inside the project window. I'm sure this is acheivable but might take a while to figure out.

Posting Permissions

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