PDA

View Full Version : VBA & Bookmark collapsed by default when opening word document



avril18
12-15-2016, 08:48 PM
I'm using VBA to insert a collapsing/ expandable section of text into a word document, which has been successful. However, even after saving the word document and code into proper .docm format, when I open the document up again, the entire bookmark is automatically opened.

I want to open the word document with the bookmark automatically closed/ collapsed by default so that the huge block of text within it is hidden unless you click it to expand. I cannot find the proper VBA code to accomplish this (or setting), and I've been working on this literally all day & want to throw my computer out the window. I'm not using headings, so any advice on that front won't help.

The code I currently have in Microsoft Word 2013 VBA is:

Public Sub MYMACRO()
ActiveDocument.Bookmarks("WorkExperience").Range.Font.Hidden = Not ActiveDocument.Bookmarks("WorkExperience").Range.Font.Hidden
End Sub

gmayor
12-16-2016, 09:41 PM
Use an autoopen macro to set the initial value


Sub AutoOpen()
ActiveDocument.Bookmarks("WorkExperience").Range.Font.Hidden = True
End If