View Single Post
 
Old 06-22-2024, 08:54 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Attached Files
File Type: docm SHED SHEET TESTING JASON.docm (40.1 KB, 2 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Guessed; 06-23-2024 at 04:16 PM.
Reply With Quote