Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2022, 12:06 PM
ranjan ranjan is offline Docx to rtf Windows 10 Docx to rtf Office 2019
Advanced Beginner
Docx to rtf
 
Join Date: May 2021
Posts: 80
ranjan is on a distinguished road
Default Docx to rtf

I want to convert the active document from .docx to .rtf and save in the active document path and save with the same active document file name.



Example:-

Input: c:\123.docx

Output: c:\123.rtf

Please help me in this regard’s…

I tried the below one but am not getting the same active file name in the same path, could you help me in this regards.

Code:
Sub rtf_test()

Dim strFname As String
Dim oDoc As Document
Dim strPath As String

    strFname = "Filename" 
    Set oDoc = ActiveDocument
    strPath = ActiveDocument.path & "\"
    
   oDoc.SaveAs2 FileName:=strPath & "Filename.rtf", FileFormat:=wdFormatRTF
   
      
End Sub
Any help is highly appreciated...

Thank you so much.
Reply With Quote
  #2  
Old 02-06-2022, 01:39 PM
spillerbd spillerbd is offline Docx to rtf Windows 10 Docx to rtf Office 2013
Competent Performer
 
Join Date: Jan 2016
Posts: 130
spillerbd is on a distinguished road
Default

You are not defining the FIle name correctly. ActiveDocument.Name
Code:
Sub rtf_test()

Dim strFname As String
Dim oDoc As Document
Dim strPath As String

    strFname = "Filename"
    Set oDoc = ActiveDocument
    strPath = ActiveDocument.Path & "\"
    
   oDoc.SaveAs2 FileName:=strPath & ActiveDocument.Name & ".rtf", FileFormat:=wdFormatRTF
   
      
End Sub
Reply With Quote
  #3  
Old 02-06-2022, 01:40 PM
spillerbd spillerbd is offline Docx to rtf Windows 10 Docx to rtf Office 2013
Competent Performer
 
Join Date: Jan 2016
Posts: 130
spillerbd is on a distinguished road
Default

I recorded the process and then updated the Name property to variable and got this code

Code:
Sub SaveAsRTF()
'
' SaveAsRTF Macro
'
'
    ChangeFileOpenDirectory _
        ActiveDocument.Path
    ActiveDocument.SaveAs2 FileName:=ActiveDocument.Name & ".RTF", FileFormat:= _
        wdFormatRTF, LockComments:=False, Password:="", AddToRecentFiles:=True, _
        WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
         SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
        False, CompatibilityMode:=0
    ActiveDocument.Close
End Sub
Reply With Quote
  #4  
Old 02-06-2022, 10:04 PM
gmayor's Avatar
gmayor gmayor is offline Docx to rtf Windows 10 Docx to rtf Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

What you need is
Code:
Sub rtf_test()
Dim oDoc As Document
Dim strPath As String
    Set oDoc = ActiveDocument
    oDoc.Save
    If Not ActiveDocument.path = "" Then
        strPath = ActiveDocument.FullName
        strPath = Left(strPath, InStrRev(strPath, Chr(46))) & ".rtf"
        oDoc.SaveAs2 FileName:=strPath, FileFormat:=wdFormatRTF
    Else
        oDoc.SaveAs2 FileName:="Filename.rtf", FileFormat:=wdFormatRTF
    End If
    Set oDoc = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 02-08-2022, 10:28 AM
ranjan ranjan is offline Docx to rtf Windows 10 Docx to rtf Office 2019
Advanced Beginner
Docx to rtf
 
Join Date: May 2021
Posts: 80
ranjan is on a distinguished road
Default

Thanks a lot for making required changes ....

It works exactly what i required....

Reply With Quote
Reply

Tags
docx, rtf

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
xml to docx yacov Word 2 04-20-2020 12:05 AM
Merge a .docx into a table in existing .docx MarkAtTheBeach Word Tables 3 10-26-2018 12:55 PM
Docx??? word perfect Word 1 01-18-2013 05:15 AM
Docx to rtf Doc v Docx Frustrated Word 3 12-12-2011 10:34 PM
Docx to rtf .docx ding dong Word 3 11-01-2009 12:43 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft