954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Convert Word document into a RichText Format document

Greetings folks,

I need to load a word document file into a RichTextBox component, It can't be done directly, so, I need first, convert it to a RichText Format File and then load it to the component. Any Ideas?

Thanks

Omar

culebrin
Junior Poster in Training
62 posts since Aug 2007
Reputation Points: 10
Solved Threads: 1
 

Hi,

Try this, I haven't been able to test it:

Dim Oword As Object
Dim Odoc As Object

Private Sub Command1_Click()
  Set Oword = CreateObject("Word.Application")
  Set Odoc = Oword.documents.open("C:\temp.doc")
  Odoc.SaveAs FileName:="c:\x.rtf", FileFormat:=wdFormatRTF
  Oword.quit

  Me.RichTextBox1.FileName = "C:\x.rtf"
End Sub
kb.net
Junior Poster
172 posts since Aug 2007
Reputation Points: 13
Solved Threads: 29
 

Thanks KB ,

But, now I can't make it work, the "wdFormatRTF" is a non recognized variable :S, I tried to look for other options, but I can't find any related (and relevant) info about those options on the "Word.Application" object, maybe you can show me how can I accomplish this. Thanks

culebrin
Junior Poster in Training
62 posts since Aug 2007
Reputation Points: 10
Solved Threads: 1
 

Hi,
Just replace the wdFormatRTF with number 6 (this code is for VB6, if you are using different IDE please advise).

Dim Oword As Object
Dim Odoc As Object

Private Sub Command1_Click()
  Set Oword = CreateObject("Word.Application")
  Set Odoc = Oword.documents.open("C:\temp.doc")
  Odoc.SaveAs FileName:="c:\x.rtf", FileFormat:=6
  Oword.quit
Me.RichTextBox1 = ""
  Me.RichTextBox1.FileName = "C:\x.rtf"
End Sub
kb.net
Junior Poster
172 posts since Aug 2007
Reputation Points: 13
Solved Threads: 29
 

Thanks man!!,

That worked great!!, now I'm trying with other formats, I'll post how i'm doing with it...

culebrin
Junior Poster in Training
62 posts since Aug 2007
Reputation Points: 10
Solved Threads: 1
 

ok i found this thread through google and im quite a novice at scripting but where exactly would i incert that bit of code you posted in my MS word documents code?

The Neophyte
Newbie Poster
1 post since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

First, it's strongly frowned upon to post to threads that are more than three months old. Even if you have a question regarding an old thread, then you would start a new thread, and post a link to the old thread with your question. This will help to ensure that you get a warm and helpful welcome instead of the inevitable flaming that is sure to follow posting to old threads.

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You