PDA

View Full Version : Where does the code go?



Scottintexas
07-07-2016, 05:56 AM
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

gmaxey
07-07-2016, 10:38 AM
16570

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

Scottintexas
07-08-2016, 05:25 AM
16570

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.

gmaxey
07-08-2016, 05:38 AM
The one called Scott Demo.docm

Scottintexas
07-08-2016, 12:34 PM
Oh crap!