Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word macro skips reading some files

Status
Not open for further replies.

trito

MIS
Jan 31, 2003
12
0
0
US
Hi,

I wrote a macro to read in all the txt files from a directory, format and convert them to and rtf format but when I run it it against a lot of files, it would randomly skip a couple. If I run the macro again the missing files would appear. Can someone please tell me how I can modify my macro so it will completely iterate through the directory?

Thanks,

Tri


Sub TxtConverter()

Dim FileName As String


FileName = Dir("H:\*.TXT")
While FileName <> &quot;&quot;
convertfiles (FileName)
FileName = Dir()
Wend

End Sub
Sub convertfiles(FileName)
'
'
ChangeFileOpenDirectory &quot;H:\&quot;
Documents.Open FileName:=FileName
With ActiveDocument.PageSetup
.PaperSize = wdPaperLegal
.Orientation = wdOrientLandscape
End With

ChangeFileOpenDirectory &quot;H:\&quot;
ActiveDocument.SaveAs FileName:=FileName & &quot;.rtf&quot;, FileFormat:= wdFormatRTF

ActiveWindow.Close
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top