Puba,
I am a beginner with VBA as well, but I have created a document with
many hidden sections.
Could you elaborate on where you are having trouble? You say that you
have already created a dropdown list and the macro that will run 'on
exit' from the dropdown. Are you saying you need help getting this
'on exit' macro to work?
The big thing I did was use bookmarks. I have enclosed my Hide &
Unhide macros below. As this was a major issue for the whole document
and I was working with a form, I may have additional steps not
required by you.
=============================================================
Sub HideEmergencyAddendum()
'
' HideEmergencyAddendum Macro
' Macro recorded 12/08/2006 by Keith
'
' Unprotect the form so the macro can work.
ActiveDocument.Unprotect Password:=""
' Go to the Emergency Addendum Section
Selection.GoTo What:=wdGoToBookmark, Name:="SectionEmergencyAddendum2"
' Hide the section.
With Selection.Font
.Name = ""
.Hidden = True
End With
' Go back to the beginning of the document.
Selection.GoTo What:=wdGoToBookmark, Name:="CommonStart"
' Protect the form without resetting all of the fields.
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
-------------------------------------------------------------------------------------------------------------------------
End Sub
Sub AddEmergencyAddendum()
'
' AddEmergencyAddendum Macro
' Macro recorded 12/08/2006 by Keith
'
' Unprotect the form so the macro can work.
ActiveDocument.Unprotect Password:=""
' Open the Emergency Addendum section by Showing all text (hidden and
unhidden - via Paragraph symbol).
ActiveWindow.ActivePane.View.ShowAll = Not
ActiveWindow.ActivePane.View.ShowAll
' Go to the Emergency Addendum Section
Selection.GoTo What:=wdGoToBookmark,
Name:="SectionEmergencyAddendum2"
' Unhide the section
With Selection.Font
.Name = ""
.Hidden = False
End With
Selection.Font.Name = ""
' Emergency Addendum is now visible - Close the Showing of all text
(hidden and unhidden - via Paragraph symbol).
ActiveWindow.ActivePane.View.ShowAll = Not
ActiveWindow.ActivePane.View. _
ShowAll
' Go back to the beginning of the Emergency Addendum Section.
Selection.GoTo What:=wdGoToBookmark, Name:="EmergencyStart"
' Protect the form without resetting all of the fields.
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End Sub