Consulting

Results 1 to 6 of 6

Thread: Convert from .docx to RTF ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location

    Convert from .docx to RTF ?

    I was wondering if there is a way to add a final line of VBA to a macro that will effectively convert the UserForm output to RTF?

    The reason that I ask is that the documents I produce have to be copied / pasted into a bespoke programme that accepts RTF. On the whole most things paste okay, the only exception being underline. For some reason it completely ignores these.

  2. #2
    Do you mean like
    ActiveDocument.SaveAs2 FileName:="c:\path\filename.rtf", FileFormat:=wdFormatRTF
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location
    Sorry, Graham, I didn't explain this well enough.

    When pressing the 'Enter' button on the UserForm, the Word document will populate as a Word document (obviously). This document will then be copied / pasted into the third party product that accepts anything as if it were in RTF already. Thus the formatting of anything with an underline (specifically) is "stripped out" leaving just the text part when pasted across from the Word formatted document.

    What I'd like to achieve is when pressing the 'Enter' button on the UserForm, the document is "formatted / coded" as a RTF document. I'm hoping then that the underlines will stay in place and will hopefully be accepted into the third party programme when copied / pasted.

    I think that makes sense to me????

  4. #4
    I am not sure that is possible, however the following may work. It saves the document, then saves it as RTF, copies the RTF file content to the clipboard, closes the RTF file and re-opens the DOCX file and deletes the temporary RTF file. Note that the code will have to be in the document template and not the document.
    Sub SaveandCopyForm()Const strPath As String = "c:\path\"
    Dim strFname As String
    Dim oDoc As Document
        strFname = "Filename"
        Set oDoc = ActiveDocument
        oDoc.SaveAs2 FileName:=strPath & strFname & ".docx", FileFormat:=wdFormatXMLDocument
        oDoc.SaveAs2 FileName:=strPath & strFname & ".rtf", FileFormat:=wdFormatRTF
        oDoc.Range.Copy
        MsgBox "Document copied to clipboard"
        oDoc.Close 0
        Documents.Open FileName:=strPath & strFname & ".docx", AddtoRecentFiles:=False
        Kill "c:\path\filename.rtf"
        Set oDoc = Nothing
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location
    Many thanks, Graham.

    I have a more pressing issue with one of my other VBA templates, but will certainly give this a try very soon.

    Steve

  6. #6
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    395
    Location
    I have given this a try and the code does what it says on the tin, but pasting into the bespoke programme ignores the underline formatting.

    I've asked some questions to see why this might be by those who administer the programme. Thankfully this is a small detail, but would be nice to have implemented.

    Thanks to Graham!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •