Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Dec 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    What if/then drop down macro

    I have a long word document (form) that i would like to shorten when particular sections dont apply. I have everything locked so users complete only legacy form fields. I wrote a very simple macro to unlock the document select all the text in a table and hide the contents then relock the file. The challenge i now have is how to run this macro. I havent been able to figure out how to connect it to a simple form field drop down so that it runs if "yes" or "no" is selected.

    I welcome any tips

  2. #2
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Willow Grove, Pennsylvania, USA
    Posts
    205
    Thanks
    4
    Thanked 49 Times in 40 Posts
    First, insert bookmarks to surround the sections of the document that you want to show or hide. You can also show/hide tables and various other parts, as long as you know how to address them in a macro.

    Next, write the macro that does the showing and hiding based on the .Result property of the dropdown field. Here's a simple example, assuming the dropdown is named ShowHide and the bookmark is named bk1:

    Code:
    Sub ExitDD()
        With ActiveDocument
            If .ProtectionType <> wdNoProtection Then
                .Unprotect Password:=""
            End If
            
            If .FormFields("ShowHide").Result = "Yes" Then
                .Bookmarks("bk1").Range.Font.Hidden = False
            Else
                .Bookmarks("bk1").Range.Font.Hidden = True
            End If
            
            .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
        End With
    End Sub
    Finally, open the Properties dialog of the dropdown, and select the macro name in the Exit Macro box. Protect the form. The macro will fire when the cursor moves from the dropdown to any other form field.

  3. #3
    New Lounger
    Join Date
    Dec 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks a ton that you took the time to reply. Im sorry my initial question maybe wasnt clear enough.

    What i have is a macro to hide the text if a form user selects "no" from the drop down and a macro that unhides the text if a form user selects "yes". I thought it would be a good idea to build in a reversal as im sure users will change their mind time to time.

    So i was hoping for guidence on adding this if/then scenario into my macro

  4. #4
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts
    Consider using a simple (or complex) IF field rather than a macro. That way you do not have problems with macro security.

    The conditional text is displayed given one answer and not displayed otherwise.

    http://office.microsoft.com/en-us/wo...102110133.aspx
    Charles Kyle Kenyon
    Madison, Wisconsin

Posting Permissions

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