Consulting

Results 1 to 5 of 5

Thread: Run Macro when Content Control Drop Down Changes

  1. #1
    VBAX Newbie
    Joined
    Aug 2012
    Posts
    2
    Location

    Run Macro when Content Control Drop Down Changes

    Hi there,

    I am working on a Word document that has a content control drop down list. Is it possible to run a macro when the user changes the item in the drop down list? I am looking to update other fields in the document based on the drop down item. If I change the item and run the macro manually, it updates fine but I was hoping to run it automatically. Any help would be appreciated!

    Thanks!

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    There is still no change event for content controls. This is the single biggest disappoint with Word2013.

    There are a couple of events that fire when a "mapped" dropdown content control changes.

    [VBA]Private Sub Document_ContentControlBeforeContentUpdate(ByVal ContentControl As ContentControl, Content As String)
    MsgBox "BeforeContentUpdate"
    ActiveDocument.Range.InsertAfter "To bad this won't work."
    End Sub
    Private Sub Document_ContentControlBeforeStoreUpdate(ByVal ContentControl As ContentControl, Content As String)
    MsgBox "BeforeStoreUpdate"
    ActiveDocument.Range.InsertAfter "To bad this won't work."
    End Sub[/VBA]


    Unfortunately though, when the application is responding to these events, the document object is not available. You'll see this if you test the code above.

    You will have to use the Exit event. This will fire when your user changes the entry and "exits" the CC.

    Or, and it is no walk in the park to understand or code, I have some examples of a work around CC change event on my website, including an example using dropdowns:
    http://gregmaxey.mvps.org/word_tip_p...om_events.html
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cross-posted at: http://www.excelforum.com/word-progr...n-changes.html
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    VBAX Newbie
    Joined
    Aug 2012
    Posts
    2
    Location
    Quote Originally Posted by gmaxey
    There is still no change event for content controls. This is the single biggest disappoint with Word2013.

    There are a couple of events that fire when a "mapped" dropdown content control changes.

    [vba]Private Sub Document_ContentControlBeforeContentUpdate(ByVal ContentControl As ContentControl, Content As String)
    MsgBox "BeforeContentUpdate"
    ActiveDocument.Range.InsertAfter "To bad this won't work."
    End Sub
    Private Sub Document_ContentControlBeforeStoreUpdate(ByVal ContentControl As ContentControl, Content As String)
    MsgBox "BeforeStoreUpdate"
    ActiveDocument.Range.InsertAfter "To bad this won't work."
    End Sub[/vba]

    Unfortunately though, when the application is responding to these events, the document object is not available. You'll see this if you test the code above.

    You will have to use the Exit event. This will fire when your user changes the entry and "exits" the CC.
    Thanks a lot for the help! Sorry for cross posting

Posting Permissions

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