Thanks Paul! I appreciate you responding to me and I saw you helped a bunch of other people around the same time. I'm so grateful there are people willing to share their knowledge.
The macro worked like a charm, thank you so much. I have a few questions though because I found additional issues once I ran it.
1. Isn't
.Text = "([0-9]{2})([0-9]{7}) looking for a 9 digit number? I have another ID number in the document that’s 10 digits that I don’t want to touch but now it gets a hyphen. How do I make the code above exclusive to 9 digit numbers?
2. Also, for the 10 digit number, how do I add text afterwards? It wouldn’t be the same parameters as the SSN number. Just a find “SSID: 1234567890” and replace with “SSID: 1234567890 (Status: Approved )”. The numbers will be different in every document which is why I want to use a macro. Right now we spend about an hour editing. Since starting to use macros it’s down to 4 hotkeys…
3. For legal reasons we have to track all changes to these documents but when I turn them on the track changes breaks the macro and instead of inserting the “-“ after the second digit it sends the hyphen to the end. I utilized your macro to adjust our student IDs which are formatted similarly to a tax id, e.g., 12-3456789 and thought I was doing something wrong when I added the code below but it was because of the track changes being on.
.Text = "([0-9]{2})([0-9]{7})"
.Replacement.Text = "\1-\2"
4. As I said, for legal reasons we have to track all changes it breaks the following macro (thank you Greg Maxey) also. If I add “ActiveDocument.TrackRevisions = True” then I get runtime error 4198. Previously when I got this error it was because there were already content controls in the document but this is a new word doc with nothing on it but words haha. Please help, I’m stumped.
Code:
Sub ReplaceWithConentControl()
Dim oRng As Word.Range
Dim strFind() As String
Dim strInput As String
Dim i As Long
Dim oCC As ContentControl
strFind() = Split("this provider|the provider", "|")
strInput = InputBox("Enter provider's last name:", "Input")
For i = 0 To UBound(strFind)
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = strFind(i)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute
Set oCC = ActiveDocument.ContentControls.Add(wdContentContro lText, oRng)
With oCC
'"Comments" property
.XMLMapping.SetMapping "ns1:coreProperties[1]/ns0:description[1]", , ActiveDocument.CustomXMLParts(1)
.Range.Text = strInput
.Title = "Name"
End With
Wend
End With
Next
End Sub
As always, any help is appreciated. Thank you for your time!
Donna Marie