Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Module Name (VBA/Word & Excel/2003)

    Stumped again!

    Can anyone tell me how (in code), to determine the name of the module which contains the code currently being run?

    T.I.A.
    Regards
    Don

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

    Re: Module Name (VBA/Word & Excel/2003)

    Offhand, I don't see a way of doing that. Why would you want to know this in code?

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Module Name (VBA/Word & Excel/2003)

    Thanks for bringing me back to Earth Hans.

    It was a Wild idea that would have saved me looking to the module name instead of just pasting in a block of code. <img src=/S/stupidme.gif border=0 alt=stupidme width=30 height=30>
    Regards
    Don

  4. #4
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Wellington, New Zealand
    Posts
    143
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Module Name (VBA/Word & Excel/2003)

    Does the following provide what you want?

    VBE.ActiveCodePane.CodeModule.Parent.Name

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

    Re: Module Name (VBA/Word & Excel/2003)

    Good try, but unfortunately it won't do what Don Wells wanted.

    VBE.ActiveCodePane.CodeModule.Parent.Name will return the name of whichever module happens to be at the front in the Visual Basic Editor (VBE) when the code is run. This is not necessarily the module that contains the macro being run - that might be in a window hidden behind others. If all code windows in the Visual Basic Editor have been closed, ActiveCodePane will cause an error.

Posting Permissions

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