![]() |
#1
|
|||
|
|||
![]()
I am a VBA novice using Office 2010.
I have a macro enabled document with all private subroutines under the ThisDocument module. The document has a series of content controls titled and tagged in a 2-dimension array like fashion, such as: [.Title = "1", .Tag = "a"], [.Title = "1", .Tag = "b"], [.Title = "1", .Tag = "c"], [.Title = "2", .Tag = "a"], [.Title = "2", .Tag = "b"], [.Title = "2", .Tag = "c"], [.Title = "3", .Tag = "a"], [.Title = "3", .Tag = "b"], [.Title = "3", .Tag = "c"] (The main reason for this is so I can run subroutines to clear the data in the content controls based on .Title or .Tag respectively.) I am writing code for the Document_ContentControlOnExit state, where I want to use the title of the content control being exited as a reference to select a certain other content control with the same title but a different tag. Example - I want to select the content control [.Title = "1", .Tag = "b"] to perform an operation on, by using the title of content control [.Title = "1", .Tag = "a"] on exit. My present thought process was to limit my initial subset of ContentControls to .Title = "1" with SelectContentControlsByTag, and then select the content control with .Tag = "b" - I am unclear how I would do this based on what I have read on the online Microsoft VBA documentation. A failed approach follows: (error is "Compile error: Method or data error not found" pointing to the last line of code) Code:
Private Sub Document_ContentControlOnExit(ByVal oCC As ContentControl, Cancel As Boolean) Dim i as String, iCC As ContentControls, jCC As ContentControl i = oCC.Title With oCC If .Tag = "a" Then Set iCC = ActiveDocument.SelectContentControlsByTag("b") Set jCC = iCC.SelectContentControlsByTitle(i)(1) === On a similar note, I wish to run a subroutine where operations are done in sequential order with reference to .Title, -> e.g. edit data of [.Title = "1", .Tag = "b"], then edit data of [.Title = "2", .Tag = "b"], etc.), with .Title being the dynamic variable and .Tag being constantly "b" in this example. My content control titles unfortunately are not in a complete numerical series (they run 1-12, E, F, then 19-20), and given they are strings I am unsure if a For statement would work. Would using a Select Case work best in this instance? |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
gsbpxw | Word VBA | 1 | 10-22-2018 12:45 PM |
VBA to provide text string with specific formating based on Drop down list (content control) | MP1989 | Word VBA | 4 | 07-30-2018 02:40 AM |
How to display tag in Content Control instead of title | vinbalraj | Word | 1 | 03-02-2018 08:55 AM |
![]() |
shammi_raj | Word | 1 | 03-10-2016 02:37 AM |
![]() |
warbird | Word VBA | 2 | 07-13-2015 05:44 AM |