If You Were Me, How Would You Do This

B

Bruce Martin

Afternoon everyone. Here's what I'm trying to do.

1. Scan every Word doc in a user selected folder.

2. Each document has an SSN in it, some where between line 10 and line 14.
Most are of the format 123 45 6789, a few are 123-45-6789.

3. I need to grab each SSN, format it as 123456789, and save them in either
a txt file, or an Excel spreadsheet.

I plan on using VB to do this but any VBA hints you can give me I should be
able to carry over to VB. I know my way around VB, but am truly new when it
comes to working with a document object.

Thanks in advance for any and all help.

Bruce
 
D

Dave Lett

Hi Bruce

Browse the Word MVP site.

1) You can open all the documents in a folder (there's an article there on how to access all the files in a directory) and search all the storyranges of a document (another article on searching the main story, header/footer, textboxes, etc.
2) Use a wildcard search (another article that provides great insight on your search parameters); you'll probably end up searching for something like "[0-9]{3,3}[ -][0-9]{2,2}[ -][0-9]{4,4}", which means find a 3-digit number, and followed by a space or a hypen, and followed by a 2-digit number, and followed by a space or a hypen, and followed by a four-digit number
3) Once you find the text, you can add it to a string, place it in a new document, and save that document as a text fil

Dim sNum As Strin
Dim oDoc As Documen
''' open a file in the director
With Selectio
.HomeKey Unit:=wdStor
With .Fin
.ClearFormattin
.Text = "[0-9]{3,3}[ -][0-9]{2,2}[ -][0-9]{4,4}
Do While .Execut
sNum = sNum & Selection.Text & vbCrL
Loo
End Wit
End Wit

''' close the fil
''' open the next file in director

sNum = Replace(Replace(sNum, "-", ""), " ", ""

Set oDoc = Documents.Ad
With oDo
.Content.Text = sNu
.SaveAs FileName:="C:\Test\Test.txt", FileFormat:=wdFormatTex
End Wit

HTH,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top