save as txt file

E

EllenM

Hello,
I have a macro that breaks up a large txt file into smaller files.
Everything is fine, except that it saves the smaller files as .docs, when I'd
like them to be saved as .txt files.

The code that I think needs fixing is:
nDoc.SaveAs Format(l, "00000") & ".doc"

My complete macro is as follows:
Sub macro8b()
Dim l As Long ' number of new docs to be created
Dim p As Long ' Number of paragraphs in source doc
Dim nDoc As Document ' a new doc
Dim rDcm As Range ' the source documents range
Set rDcm = ActiveDocument.Range
p = rDcm.Paragraphs.Count
While p > 1
l = l + 1
Selection.GoTo _
What:=wdGoToLine, _
Which:=wdGoToAbsolute, _
Count:=3500
With Selection.Find
.Execute FindText:="Doctype"
End With
Selection.MoveUp Unit:=wdLine, Count:=1
rDcm.Start = 0
rDcm.End = Selection.Bookmarks("\line").Range.End
Set nDoc = Documents.Add
nDoc.Range.InsertAfter rDcm.Text
rDcm.Delete
nDoc.SaveAs Format(l, "00000") & ".doc"
nDoc.Close
Set rDcm = ActiveDocument.Range
p = rDcm.Paragraphs.Count
Wend
End Sub

Thanks in advance for your help!!

EllenM
 
J

Jay Freedman

Yes, that's the line you need to change. There are two things: the
file extension should be .txt instead of .doc, and you need to tell
Word that the file format should be text instead of the default Word
document format. The line should be

nDoc.SaveAs FileName:=Format(l, "00000") & ".doc", _
FileFormat:=wdFormatText

(Note that there's a space between the comma and the underscore at the
end of the first line. This tells VBA that both lines are part of the
same statement.)

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
E

Ellen

Thanks for your help, Jay. You code worked!!

Jay Freedman said:
Yes, that's the line you need to change. There are two things: the
file extension should be .txt instead of .doc, and you need to tell
Word that the file format should be text instead of the default Word
document format. The line should be

nDoc.SaveAs FileName:=Format(l, "00000") & ".doc", _
FileFormat:=wdFormatText

(Note that there's a space between the comma and the underscore at the
end of the first line. This tells VBA that both lines are part of the
same statement.)

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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