View Full Version : Run Macro when Content Control Drop Down Changes
hawk123
08-23-2012, 07:46 AM
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!
gmaxey
08-23-2012, 02:22 PM
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.
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
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_pages/content_control_custom_events.html
macropod
08-23-2012, 03:10 PM
Cross-posted at: http://www.excelforum.com/word-programming-vba-macros/855177-run-macro-when-content-control-drop-down-changes.html
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
macropod
08-23-2012, 07:01 PM
Also cross-posted at: http://www.mrexcel.com/forum/general-excel-discussion-other-questions/655211-word-run-macro-when-content-control-drop-down-changes.html (http://www.mrexcel.com/forum/general-excel-discussion-other-questions/655211-word-run-macro-when-content-control-drop-down-changes.html)
hawk123
08-24-2012, 06:08 AM
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.
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
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 :(
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.