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)
Is there a method by which I can query both .Tag and .Title simultaneously to find the content control of interest, or am I restricted to filtering based on one at a time? If the latter, how would I choose the correct control and how would this be coded (compared with my attempt above)?
===
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?