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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save files from *.doc to *RTF

Status
Not open for further replies.

magnum79

Technical User
Jan 20, 2006
1
GB
Hi all,

This is my first post and I'm trouble saving my documents. Id like to save all *.doc documents in a specific location to *.rtf files. I can do 1 at a time in a macro but really need a macro/batch file that says:

Take all word docs in this location and change them to rtf files and save.

Any help would be much appreciated.

Thanks
 
Code:
'...
Dim strFileName As String
'...
strFileName = Dir("[i]YourPathHere[/i]\*.doc")
Do
  strFileName = Dir
  'Do your code here on each new file found
Loop Until Len(strFileName) = 0
'...

Hope this helps,
CMP

Funny thing about being unemployed, weekends don't mean quite so much, just means you get to hang out with your working friends. Primus
 
A small alternative:
Code:
Sub ToRTF()
Dim oFile
Dim myPath As String
myPath = "C:\test\"
oFile = Dir(myPath & "*.doc")
Do While oFile <> ""
  Documents.Open FileName:=myPath & oFile
  With ActiveDocument
[COLOR=red]' need to strip off ".doc" from OFile[/color red]
   .SaveAs FileName:=myPath & Left(oFile, Len(oFile) - 4), _
       Fileformat:=wdFormatRTF
   .Close
  End With
  oFile = Dir
Loop
End Sub
You could also pass in the specific folder as a parameter, say taken in as an Inputbox value.

Code:
Sub ToTRF (sFolder As String)
Dim oFile
oFile = Dir(sFolder & "*.doc")
........
End Sub

Sub MakeRTF()
Dim sFolder As String
sFolder = Inputbox("Enter folder name.")
Call (sFolder)
End Sub
Although you would, of course, have to do error trapping on the folder string.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top