Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
' This code creates an RTF document in the next to last line.  This requires
' that Word is installed.  Is there a different way that requires only Wordpad
' because it is usually present when office is not installed?

' Create document.
        WordApp = CreateObject("Word.Application")

        If WordApp.Visible = True Then WordApp.Visible = False
        WordApp.Assistant.Visible = False
        thisDoc = WordApp.Documents.Add
        thisDoc.PageSetup.PaperSize =    Microsoft.Office.Interop.Word.WdPaperSize.wdPaperLetter
        thisDoc.PageSetup.TopMargin = 0
        thisDoc.PageSetup.BottomMargin = 0
        thisDoc.PageSetup.HeaderDistance = 0
        thisDoc.PageSetup.FooterDistance = 0
        thisDoc.PageSetup.LeftMargin = 72
        thisDoc.PageSetup.RightMargin = 72
        thisDoc.Range.InsertBefore(currentName)
        thisRange = thisDoc.Paragraphs.Item(1).Range
        thisRange.Font.Name = "Segoe UI Semibold"
        thisRange.Font.Bold = True
        thisRange.Font.Size = 14
        thisRange.ParagraphFormat.Alignment _
      = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft

        ' Save document.
        frmSrv1.Text = "Saving document..."
        TopicFileName = topicDir & "\" & srvFilesFldN & "\" & progID & thisAppID & topicN & "." & srvExt
        thisDoc.SaveAs(TopicFileName, RichTextBoxStreamType.RichText)
        thisDoc.Close
Posted

1 solution

Rtf file is MS Word independent. Please see: http://en.wikipedia.org/wiki/Rich_Text_Format[^] - Implementations section. Fianlly, i need to warn you: "The RTF specifications lack some of the semantic definitions necessary to read, write and modify documents."

I'd suggest to use OpenXML, see: How to: Manipulate Office Open XML Formats Documents[^]
 
Share this answer
 
Comments
VSNetVbHarry 15-Mar-15 13:05pm    
The question could be changed to: 'Can I programatically open an .rtf document and manipulate the text without having MS Office installed. I can do this by opening the .rtf document with Wordpad only, but can I do this programatically on a computer that does not have MS Office? VSNetVbHarry
Maciej Los 15-Mar-15 18:30pm    
Please, read this: http://stackoverflow.com/questions/11220275/open-source-richtext-control-for-net
http://www.codeproject.com/Articles/27431/Writing-Your-Own-RTF-Converter
VSNetVbHarry 16-Mar-15 19:52pm    
This will do for now while I evaluate the download of the Converter. Thanks to Maciej Los for this response.
Maciej Los 17-Mar-15 2:44am    
You're very welcome ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900