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

Saving rtf as a text file????

Status
Not open for further replies.

cjhepburn

Technical User
Mar 9, 2001
8
US
''''Does anyone have any idea why this won't save as a text file?

Sub OpenWord()
Dim AccApp As Object
Dim test As String
Dim junk As String
input = "c:\crap.rtf"
output = "c:\junker.txt"
Set AccApp = CreateObject("Word.Application")
AccApp.Visible = True
AccApp.Documents.Open FileName:=input
AccApp.ActiveDocument.SaveAs FileName:=output, _
FileFormat:=wdFormatText, LockComments:=False, _ AddToRecentFiles:=False, ReadOnlyRecommended:=False, _ EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, _ SaveAsAOCELetter:=False
AccApp.Application.Quit
End Sub
 
dear it will not directly , but if you want to rename the file, it can be done at browser, but renaming of file can not change the format of the same..

hiren
 
To answer my own question, if anyone else has this problem.
I've also included the comments so that you know the order of the properties.

Sub OpenWord()
Dim AccApp As Object
Dim test As String
Dim junk As String
test = "c:\2AirProdcorpd.rtf"
junk = "c:\junker.txt"
Set AccApp = CreateObject("Word.Application")
'AccApp.Visible = True
'AccApp.Documents.Open filename:=test
AccApp.Documents.Open test
'AccApp.ActiveDocument.SaveAs FileName:=junk, FileFormat:=2
AccApp.ActiveDocument.SaveAs junk, 2
AccApp.Application.Quit
End Sub
 
I'd presume the problem was due to naming a variable input and as I'm sure you are aware, input is a VBA function name.

In your resolution, you changed the variable name to test and that's probably what alleviated your problem. Jon Hawkins
 
Actually no, that was a typo as I was trying to make the code more readable for this forum.
What the problem was, is that "FileFormat:=wdFormatText" was not being recognized; "FileFormat:=2" works though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top