Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Michigan, USA
    Posts
    408
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi everyone,
    This is my first time posting since the lounge changed. I like it!!

    I want to create a macro that will toggle the Document Map in two specific documents. So when I open Document 1 it would close Document Map if it is open, and when I open Document 2 it would turn on Document Map if it isn't already on. I guess all other Documents, including new ones, would have the Document Map off. Can you do such a thing in Word? I know how to make a document specific macro in Excel but I can't figure out if Word acts the same way.

    Thanks.
    <font face="Comic Sans MS"><big><font color=4682b4>Sherry</font color=4682b4></big></font face=comic>

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='sobershe' post='766881' date='23-Mar-2009 12:16']I want to create a macro that will toggle the Document Map in two specific documents. So when I open Document 1 it would close Document Map if it is open, and when I open Document 2 it would turn on Document Map if it isn't already on. I guess all other Documents, including new ones, would have the Document Map off. Can you do such a thing in Word? I know how to make a document specific macro in Excel but I can't figure out if Word acts the same way.[/quote]
    You can create a macro in your general macro container (Normal.dot) that runs automatically every time a document opens. This happens if you name the macro AutoOpen(). You can check either the name or the complete path+name of the file, as needed. Check out the ActiveDocument object for specifics.

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    [quote name='sobershe' post='766881' date='23-Mar-2009 19:16']I want to create a macro that will toggle the Document Map in two specific documents. So when I open Document 1 it would close Document Map if it is open, and when I open Document 2 it would turn on Document Map if it isn't already on.[/quote]
    I think you will need to create code that is triggered by the Document Activate event to deal with the situation where a user opens multiple documents and switches between them.

  4. #4
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Michigan, USA
    Posts
    408
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='jscher2000' post='766888' date='23-Mar-2009 16:07']You can create a macro in your general macro container (Normal.dot) that runs automatically every time a document opens. This happens if you name the macro AutoOpen(). You can check either the name or the complete path+name of the file, as needed. Check out the ActiveDocument object for specifics.[/quote] I already have an AutoOpen() so can AutoOpen() do more than one thing? Below is the current AutoOpen() followed by an attempt to write the code to check for the file name and open/close the Document Map.
    Sub AutoOpen()
    Application.GoBack
    End Sub
    This is my code for Document Map. It only checks for one file name - I figured I'd start small since I haven't really done much with Word macros. I will have to include another If, Then, Else for the 2nd scenario since one file uses the Document Map and the other doesn't. If I am anywhere near using the correct code would I add it after the Application.GoBack line?

    If ActiveDocument.Name = "DocA" Then
    ActiveDocument.ActiveWindow.DocumentMap = True
    Else
    ActiveDocument.ActiveWindow.DocumentMap = False Thanks.
    <font face="Comic Sans MS"><big><font color=4682b4>Sherry</font color=4682b4></big></font face=comic>

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='sobershe' post='767889' date='27-Mar-2009 16:18']I already have an AutoOpen() so can AutoOpen() do more than one thing?[/quote]
    Oh yes, many things. I believe Application.GoBack repositions the insertion point. I don't know whether you would want to run that before or after your code to display/hide the Document Map. I guess try it both ways and see which works best.

    Edit: Your code block appears to be missing End If at the end, but that might just be a glitch in pasting it here in the Lounge. The compiler will let you know.

  6. #6
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Michigan, USA
    Posts
    408
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='jscher2000' post='767893' date='27-Mar-2009 19:31']Oh yes, many things. I believe Application.GoBack repositions the insertion point. I don't know whether you would want to run that before or after your code to display/hide the Document Map. I guess try it both ways and see which works best.

    Edit: Your code block appears to be missing End If at the end, but that might just be a glitch in pasting it here in the Lounge. The compiler will let you know. [/quote]

    I did miss the End IF, thanks. I put the code before Application.GoBack since I figured it should check the file name first. And it works like a charm. It probably seems silly to bother with this, but I get tired of constantly turning Document Map off since I only use it in one document.

    Thanks all for the help.
    <font face="Comic Sans MS"><big><font color=4682b4>Sherry</font color=4682b4></big></font face=comic>

Posting Permissions

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