Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 02-09-2022, 10:20 PM
gmayor's Avatar
gmayor gmayor is offline Mingle legacy fields and content controls so external program can insert data at bookmarks Windows 10 Mingle legacy fields and content controls so external program can insert data at bookmarks Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

I wouldn't recommend using CCs and legacy form fields in the same document. They achieve the form functionality in different ways. Legacy form fields require the form to be protected for forms. CCs do not and as Andrew has suggested, do not provide the tabbed access when so protected.They provide that when Editors are applied and the document is protected as read only.

You can however bookmark the content control and you can lock the control against deletion. My CC Tools add-in Insert Content Control Add-In has a module to convert legacy form fields to rich text controls retaining the bookmark names (though the controls themselves are not bookmarked).

The bookmarking can be achieved easily enough with a simple macro. (Macro1 below). You can then use the option to add editors and protect the form. Test the outcome with Macro2. This will write the same value to all the controls. If you are happy with the result, you can clear the test values with macro3.

You will need the form password, if any, to convert form fields to content controls.

Frankly content controls are rather more robust than legacy form fields and if your third party application will work with them when bookrmarked (if it just writes to named bookmarks, it almost certainly should) that would be the way to go.

I suggest you experiment with a copy of the form.
Code:
Sub Macro1()
Dim oCC As ContentControl
    For Each oCC In ActiveDocument.ContentControls
        oCC.Range.Bookmarks.Add oCC.Title
    Next oCC
    Set oCC = Nothing
End Sub

Sub Macro2()
Dim i As Integer
Dim sName As String
Dim oBM As Bookmark
    For i = 1 To ActiveDocument.Bookmarks.Count
        sName = ActiveDocument.Bookmarks(i).Name
        FillBM sName, "This is a test"
    Next i
End Sub

Sub Macro3()
Dim oCC As ContentControl
    For Each oCC In ActiveDocument.ContentControls
        oCC.Range.Text = ""
    Next oCC
    Set oCC = Nothing
End Sub


Public Sub FillBM(strbmName As String, strValue As String)
'Graham Mayor - https://www.gmayor.com
Dim oRng As Range
    With ActiveDocument
        On Error GoTo lbl_Exit
        If .Bookmarks.Exists(strbmName) = True Then
            Set oRng = .Bookmarks(strbmName).Range
            oRng.Text = strValue
            oRng.Bookmarks.Add strbmName
        End If
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 

Tags
control, legacy



Similar Threads
Thread Thread Starter Forum Replies Last Post
insert the 2 content controls into a Repeating Section in a table smaccharoli Word VBA 2 02-27-2018 08:49 AM
Mingle legacy fields and content controls so external program can insert data at bookmarks How to insert bookmarks for content or Text of ContentControl lvganesh Word VBA 5 12-12-2017 11:27 PM
How can I set up tab to go back and forth between legacy fields and content control fields in a Word Ikajed Word 1 10-13-2017 06:06 PM
Creating a Report Template / User Form and/or Content Controls with repetitive data throughout 53bigdog Word VBA 1 04-05-2016 04:00 PM
Insert image icons are showing up on images that have content controls but only on some computers. mandylach Word 0 11-10-2014 07:44 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:25 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