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 <> ""
convertfiles (FileName)
FileName = Dir()
Wend
End Sub
Sub convertfiles(FileName)
'
'
ChangeFileOpenDirectory "H:\"
Documents.Open FileName:=FileName
With ActiveDocument.PageSetup
.PaperSize = wdPaperLegal
.Orientation = wdOrientLandscape
End With
ChangeFileOpenDirectory "H:\"
ActiveDocument.SaveAs FileName:=FileName & ".rtf", FileFormat:= wdFormatRTF
ActiveWindow.Close
End Sub
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 <> ""
convertfiles (FileName)
FileName = Dir()
Wend
End Sub
Sub convertfiles(FileName)
'
'
ChangeFileOpenDirectory "H:\"
Documents.Open FileName:=FileName
With ActiveDocument.PageSetup
.PaperSize = wdPaperLegal
.Orientation = wdOrientLandscape
End With
ChangeFileOpenDirectory "H:\"
ActiveDocument.SaveAs FileName:=FileName & ".rtf", FileFormat:= wdFormatRTF
ActiveWindow.Close
End Sub