Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-29-2019, 01:05 PM
ZaSpai ZaSpai is offline Finding specific Content Control based on both title and tag Windows 8 Finding specific Content Control based on both title and tag Office 2010
Novice
Finding specific Content Control based on both title and tag
 
Join Date: Mar 2019
Posts: 2
ZaSpai is on a distinguished road
Default Finding specific Content Control based on both title and tag

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?
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding specific Content Control based on both title and tag Automating entries based on the entry in a Content Control 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
Finding specific Content Control based on both title and tag Finding field names in a Word-Form created by content control shammi_raj Word 1 03-10-2016 02:37 AM
Finding specific Content Control based on both title and tag Code to Sum Column of Content Control Values In Specific Tables? warbird Word VBA 2 07-13-2015 05:44 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft