• Document Specific Macro?

    • This topic has 5 replies, 3 voices, and was last updated 16 years ago.
    Author
    Topic
    #458509

    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.

    Viewing 1 reply thread
    Author
    Replies
    • #1153144

      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.

      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.

      • #1153869

        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.

        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 [indent] [/indent] Thanks.

        • #1153873

          I already have an AutoOpen() so can AutoOpen() do more than one thing?

          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.

          • #1154065

            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.

            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.

    • #1153146

      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 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.

    Viewing 1 reply thread
    Reply To: Document Specific Macro?

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: