Quote:
Originally Posted by dmarie123
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?
|
To exclude longer number strings and non-SSN strings, try using:
.Text = "(SSN[: ]{1,2}[0-9]{3})([0-9]{2})([0-9]{4})"
Quote:
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 )”.
|
Try adding:
Code:
'Fix SSIDs
.Text = "SSID[: ]{1,2}[0-9]{10}"
.Replacement.Text = "^& (Status: Approved )"
.Execute Replace:=wdReplaceAll
before:
'Fix Date ranges
Quote:
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"
|
Track changes does create problems! What you might try with the SSNs, for example, is:
Code:
'Fix SSNs
ActiveDocument.TrackRevisions = False
.Text = "(SSN[: ]{1,2}[0-9]{3})([0-9]{2})([0-9]{4})"
.Replacement.Text = "\1-\2-\3"
.Execute Replace:=wdReplaceAll
ActiveDocument.TrackRevisions = True
.Text = "[0-9]{3}-[0-9]{2}-[0-9]{4}"
.Replacement.Text = "^&"
.Execute Replace:=wdReplaceAll
This will give you a correctly formatted output and, whilst the tracked change won't exactly represent that only the hyphens were added, at least it will show that something was changed. If this approach is acceptable, we can extend it to the other scenarios.