+ Reply to Thread
Results 1 to 8 of 8

How to execute a Macro from a ComboBox - Word 2007

  1. #1
    Registered User
    Join Date
    11-30-2012
    Location
    Midlands
    MS-Off Ver
    2007
    Posts
    5

    How to execute a Macro from a ComboBox - Word 2007

    I am in the process of creating templates to use for standardizing our report format at work. I have so far created quite a decent Macro enabled Template (it needs to be a template as I've got complex tables as Quick Parts and simple Macros to add the tables in what could be a varied order). One cell is where I want to enter a Risk Rating, either High Medium or Low and have the cell shading Red, Orange or Green accordingly. I realise there is no conditional formatting within Word, I do not want to insert an Excel Spreadsheet for the sake of 1 cell and do not want to protect the document. I now have three simple Macros that SELECT the current cell and change the shading to one of the three colours and a COMBOBOX in the relevant cell with the options High, Medium, Low. What I CAN'T do is get one of these macros to run depending on the option in the combobox selected. Do I need to use the ComboBox on the developer tab or A Legacy one? Can anyone PLEASE shed some light on how to run the macro from the option selected (step by step, examples of code etc GREATLY appreciated)

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to execute a Macro from a ComboBox - Word 2007

    Assuming you're using a Content Control Combo List or DropDown List, you trigger the updates via a ContentControlOnExit macro in the Document/Template 'ThisDocument' code module. For example:
    Please Login or Register  to view this content.
    An alternative approach, that doesn't rely on a Content Control Combo List or DropDown List, is to hook into Word's 'DocumentChange' event. See attached.
    Attached Files Attached Files
    Last edited by macropod; 12-01-2012 at 03:35 AM.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    11-30-2012
    Location
    Midlands
    MS-Off Ver
    2007
    Posts
    5

    Re: How to execute a Macro from a ComboBox - Word 2007

    Thanks for the quick reply. The code works a treat!!!

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to execute a Macro from a ComboBox - Word 2007

    For something more efficient and flexible on the content control front, try:
    Please Login or Register  to view this content.
    With this, you can have multiple content controls whose names begin with 'Risk' and each one will respond the same way.
    Last edited by macropod; 12-02-2012 at 07:36 PM. Reason: typo

  5. #5
    Registered User
    Join Date
    11-30-2012
    Location
    Midlands
    MS-Off Ver
    2007
    Posts
    5

    Re: How to execute a Macro from a ComboBox - Word 2007

    Quote Originally Posted by macropod View Post
    For something more efficient and flexible on ther content control front, try:
    Please Login or Register  to view this content.
    With this, you can have multiple content controls whose names begin with 'Risk' and each one will respond the same way.
    This is the perfect solution as the table where the Risk Rating appears is a Quick Part and will be inserted into the final report ANY number of times depending on what we encounter when we inspect our clients sites. It works perfectly, thank you for your time.

  6. #6
    Registered User
    Join Date
    11-30-2012
    Location
    Midlands
    MS-Off Ver
    2007
    Posts
    5

    Re: How to execute a Macro from a ComboBox - Word 2007

    Hello again!! The code above (for multiple "Risk" drop-downs) is working an absolute treat. I have a cover page on this document which is filled with document properties from the QuickParts menu. This then populates the header from page 3 onwards (various section breaks inc TOC). I have researched and found this code to make the document Title (which HAS to be specific and therefore a Combobox to avoid typos) appear in the "title" Area of the header (with use of a bookmark)

    Please Login or Register  to view this content.
    This has been planted in the ThisDocument section in the Macro editor and on it's own does the trick perfectly. However when I have that code and the "Risk" code from my previous quote together (on the same This Document section) I get the following error: COMPILE ERROR: AMBIGUOUS NAME DETECTED: Document_ContentControlOnExit"

    I'm wandering around in the dark and now have two pieces of the puzzle, they work independantly of each other but can't get them to co-exist. Does anyone have any ideas please?

  7. #7
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to execute a Macro from a ComboBox - Word 2007

    You can combine them thus:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-30-2012
    Location
    Midlands
    MS-Off Ver
    2007
    Posts
    5

    Re: How to execute a Macro from a ComboBox - Word 2007

    Quote Originally Posted by macropod View Post
    You can combine them thus:
    Please Login or Register  to view this content.
    Thank you for your kind help... will have a go with this later and see what happens! Thanks again

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1