How to save a file as text in the document using a macro

T

Tony

I have 25 documents that I open and reformat with a macro. Each
document has a specific 10 digit number. How can I run one macro on
each file and have it save the file as a specific name. ex. If .Text =
"12354678" I want to save the doc as FFTC if .Text = "87654321" then
save as ZZLC. Help please just a point in the right direction can help
Thanks
 
H

Harold Kless

Hi Tony,
I'm thinking you can use a Select case statement.
Something like this
Sub foo()
Dim x As String
x = 123456
Select Case x
Case 23456
MsgBox "fft"
Case 123456
MsgBox "xyz"
Case 76554
MsgBox "rlf"
Case Else
MsgBox "no match"

End Select
End Sub

Regards,
Harold Kless, MCSD
Support Professional
Microsoft Technical Support for Business Applications
(e-mail address removed)

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

The information in the article "Find & ReplaceAll on a batch of documents in
the same folder" at:

http://word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

will show you how to operate on all of the files in a folder.

The code to do the find/save would be something like

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{10}", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
If Selection.Range = 1234567890 Then
ActiveDocument.SaveAs "FFTC"
Exit Sub
Else
ActiveDocument.SaveAs "ZZLC"
Exit Sub
End If
Loop
End With

You will however have to graft that into the info in the referenced article.

Not your example only contained an 8 digit number. What are you going to do
about overwriting the documents that have already been saved.
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
T

Tony

Thank you guys for your help, Doug's way helped and esp the auto file
open and save link. Thank's again.

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS said:
The information in the article "Find & ReplaceAll on a batch of documents in
the same folder" at:

http://word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

will show you how to operate on all of the files in a folder.

The code to do the find/save would be something like

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{10}", MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
If Selection.Range = 1234567890 Then
ActiveDocument.SaveAs "FFTC"
Exit Sub
Else
ActiveDocument.SaveAs "ZZLC"
Exit Sub
End If
Loop
End With

You will however have to graft that into the info in the referenced article.

Not your example only contained an 8 digit number. What are you going to do
about overwriting the documents that have already been saved.
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
Tony said:
I have 25 documents that I open and reformat with a macro. Each
document has a specific 10 digit number. How can I run one macro on
each file and have it save the file as a specific name. ex. If .Text =
"12354678" I want to save the doc as FFTC if .Text = "87654321" then
save as ZZLC. Help please just a point in the right direction can help
Thanks
 

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