![]() |
#8
|
||||
|
||||
![]()
Your code adds text alongside the bookmark, not inside the bookmark so it is hard to then clear that with other code. Rather than doing the extra steps to rectify that, I'm going to suggest what I consider a better alternative.
Your sample document doesn't include any code or userform information so it isn't immediately apparent what benefit you get out of using VBA so I'm going to suggest you perhaps consider getting rid of all the complexity of the userform and VBA and just go back to basics. 1. Set up your document with Content Controls instead of bookmark locations 2. Protect the document so the user can only edit the Content Controls 3. Save the document as a template so that you create new docs each time you want a 'cleared' form. An alternative to #3 is to include a macro to clear the Content Controls (aka your original request before I drifted off on a tangent because bookmarks weren't as flexible as content controls and you haven't yet convinced me as to why a VBA userform was involved). Macros to clear all CCs or write to a specific one are below Code:
Sub ClearCCs() Dim aCC As ContentControl For Each aCC In ActiveDocument.ContentControls aCC.Range.Text = "" Next aCC End Sub Sub WriteToCC() Dim aCC As ContentControl For Each aCC In ActiveDocument.SelectContentControlsByTitle("Rego") aCC.Range.Text = "This is the rego" Next aCC End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia Last edited by Guessed; 06-23-2024 at 04:16 PM. |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Rafi | Word VBA | 20 | 01-20-2023 02:16 PM |
Clear all content controls (Text, dropdown) AND change option button values to FALSE in MS Word Form | Janet D | Word VBA | 7 | 01-14-2023 02:36 AM |
Clear Values from All Controls on Form | ScottyBee | Word VBA | 2 | 04-02-2019 09:55 AM |
![]() |
sfitzsimmons | Word VBA | 1 | 01-11-2019 02:03 PM |
![]() |
BruceM | Word | 5 | 10-06-2016 08:26 AM |