save a rtf file with a different extension

Hi experts
I have 5 rtf files i want to save with different extension so they cannot be opened with word. i need to have these files renamed
with a rtf extension when recalled. I know that they can be opened with word if a user changes to rtf extension. This is okay
please help
isnoend2001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael_DCommented:
Try this:
OldName = "C:\OLDFILE.RTF"
NewName = "C:\NEWFILE.NOTRTF"
Name OldName As NewName  
Shiju SasidharanSenior IT DeveloperCommented:
'Goto Project Menu -> Reference
'and select refrences
'
'      Microsoft Scripting Runtime
'--------------------------------------------
Private Sub Command1_Click()
Dim objFso As New FileSystemObject
    If objFso.FileExists("C:\File1.rtf") Then
   
        objFso.MoveFile "C:\File1.rtf", "C:\File2.xyz"
       
    End If
End Sub
veeru_friendCommented:
'Goto Project Menu -> Reference
'and select refrences
'
'      Microsoft Scripting Runtime
'--------------------------------------------

'The below example, cmdRemoveRTF_Click will rename all rtf files in c:\ to ftr
and cmdAddRTF_click will rename all ftr filles to rtf

Private Sub cmdAddRTF_Click()
Dim objFso As New FileSystemObject
Dim File1 As File, Dir1 As Folder

Set Dir1 = objFso.GetFolder("c:\")

For Each File1 In Dir1.Files

    If LCase(objFso.GetExtensionName(File1.Path)) = "ftr" Then
        File1.Name = Replace(File1.Name, ".ftr", ".rtf")
    End If
   
Next

End Sub

Private Sub cmdRemoveRTF_Click()

Dim objFso As New FileSystemObject
Dim File1 As File, Dir1 As Folder

Set Dir1 = objFso.GetFolder("c:\")

For Each File1 In Dir1.Files

    If LCase(objFso.GetExtensionName(File1.Path)) = "rtf" Then
        File1.Name = Replace(File1.Name, ".rtf", ".ftr")
    End If
   
Next
 
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

isnoend2001Author Commented:
Thanks guys
I have been trying to avoid using fso for file handling. Why? I am a retired roofing contractor and have written a few estimating programs in VB6. I have only learned what i have needed thru books, planet, web and here. I have a few file routines, random
and binary and so far have been sufficent. I have found that sometimes new routines come in conflict with deployment and
need to be tested throughly. Like: will scripting work on win95? and be the correct version? win.me?
Is there any way to do what i need without fso?
If i must use fso then i know the name of the 5 files and know they will be located in App.path.
here is exactly what i am trying to do.
click cmdSave and rtf file will be saved as maybe App.path & "myfile.ftr"
click cmdOpen and file will be renamed to "myfile.rtf" and opened
click cmdsave file will be renamed to "myfile.ftr"
isnoend2001Author Commented:
Thanks guys
i found a better solutation using api
Declare Function MoveFile Lib "kernel32" Alias "MoveFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String) As Long

save
rtbMain.SaveFile App.Path & "\ChangeOrder.rtf", rtfRTF
MoveFile App.Path & "\ChangeOrder.rtf", App.Path & "\ChangeOrder.pro"

get
MoveFile App.Path & "\ChangeOrder.pro", App.Path & "\ChangeOrder.rtf"
rtbMain.LoadFile App.Path & "\ChangeOrder.rtf", rtfRTF
isnoend2001Author Commented:
Hi
I have found that i can remove the move file from save by saving with .pro extension
save
rtbMain.SaveFile App.Path & "\ChangeOrder.pro", rtfRTF
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.