Results 1 to 5 of 5
  1. #1
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Determine name of document holding macro (Word 2000)

    Hi,

    How can I tell in which document or template the code I'm running is stored?

    When I'm running from the VB IDE, VBE.ActiveProject.Name gives a consistent result of "Project"- but when I put the event into Normal.dot Document_Open and Document_Close, I get inconsistent results.

    Is there another way of telling?

    I want to delete code if the code resides in another document which is not the one I'm running.

    Thanks
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determine name of document holding macro (Word 2000)

    Isn't that Application.MacroContainer ?

    MS: Returns a Template object or Document object that represents the template or document in which the module that contains the running procedure is stored. Read-only.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determine name of document holding macro (Word 2000)

    Macrocontainer still does not work properly if the code is in a global template.

    Using THisDocument is safer.

  4. #4
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determine name of document holding macro (Word 2000)

    Kevin,

    That worked. Thanks.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  5. #5
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determine name of document holding macro (Word 2000)

    Howard,

    ThisDocument does not give the right answer if the object "ThisDocument" has been manually renamed (probably rare, but it dod happen). But I can use that to my advantage.

    I'm running code to delete code from other modules- and I don't want the code run if the activedocument is the one containing the code. So if I rename "ThisDocument" to "ThisMacroDicument", it will abort if ThisMacroDocument = ActiveDocument.name OR if MacroContainer.name <> ActiveDocument.Name. That should cover the situation where the code is in a global template.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

Posting Permissions

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