Consulting

Results 1 to 5 of 5

Thread: Where does the code go?

  1. #1

    Where does the code go?

    I'm not new to VBA but I am new to using VBA with word. When I go to the VBA my project explorer shows a Normal and a Project folder. I have several bookmarks in my document and I put macrobuttons in the document to collapse and expand the paragrpahs which are the bookmarks. For example:

    Sub WriteRangeNamesToSheet()
        ActiveDocument.Bookmarks("WriteRangeNamesToSheet").Range.Font.Hidden = _
        Not ActiveDocument.Bookmarks("WriteRangeNamesToSheet").Range.Font.Hidden
    End Sub
    This is the documentation for some code I had written for an excel application. I have this code in the "Project/ThisDocument" folder. There are several of these since I couldn't figure out how to use a common routine and pass a parameter. Some of them work, some don't. My macro button looks like:

    {MACROBUTTON WriteNamesToSheet >}

    When I double click the > some work, others don't. I wrote a little routine and called it from the immediate window to expand all of the paragraphs.
    Sub OpenAll()
    Dim bod As Object
    For Each bod In ActiveDocument.Bookmarks
        bod.Range.Font.Hidden = False
    Next
    End Sub
    This worked as written. I added {MACROBUTTON OpenAll [Click to Expand]} to my document and hit Alt-F9. When I double click or just single click on [Click to Expand] nothing happens. I set a break point and the sub is never called. Does this sub go into the Normal/ThisDocument or the Project/ThisDocument?

    What would make the macrobutton NOT call the sub? Is Macrobutton case sensitive. I have not found any decent documentation. I read the documentation on passing arguments using Private and AddIn. But neither example worked. The Addin example just showed {MACROBUTTON MyMacro [Click]{AddIn}}. I don't know where the added argument is.

    I would like this seemingly simple thing to work. A little experienced insight would be appreciated.

    Thanks,

    Scott

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    Scott Demo.docm

    Scott, You an put the code in the ThisDocument module of the active document project or standard module of that project. See attached.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    Quote Originally Posted by gmaxey View Post
    Scott Demo.docm

    Scott, You an put the code in the ThisDocument module of the active document project or standard module of that project. See attached.
    Which attachment? Your web site link in your signature? I browsed there and didn't see an answer to my query. I'll keep looking, but I didn't have time to read all of the information.

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    The one called Scott Demo.docm
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    Oh crap!

Posting Permissions

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