how to open word(microsoft word) to richtextbox in vb.net?

BradleyOng83

Member
Joined
Mar 2, 2006
Messages
19
Programming Experience
Beginner
how to open word(microsoft word) to richtextbox in vb.net? i just know open word use vb.net only
 
I'm sure you can do this using the clipboard. Though i havent done it myself. I found a code snippet that was in c# that may help. Done a quick translation so i think this i right....

VB.NET:
Dim app As Word.Application =  New Word.ApplicationClass() 
'Refs to pass to the Open method for parameters we're not interested in.
Dim Nothingobj As Object =  System.Reflection.Missing.Value 
 
'Full file path.
Dim file As Object =  "C:\MyDoc.doc" 
 
Word.Document doc = app.Documents.Open(
  file,  Nothingobj,  Nothingobj, 
  Nothingobj,  Nothingobj,  Nothingobj, 
  Nothingobj,  Nothingobj,  Nothingobj, 
  Nothingobj,  Nothingobj,  Nothingobj, 
  Nothingobj,  Nothingobj,  Nothingobj)
 
'Select and copy text to clipboard.
doc.ActiveWindow.Selection.WholeStory()
doc.ActiveWindow.Selection.Copy()
 
Dim data As IDataObject =  Clipboard.GetDataObject() 
'Do whatever with the text.
Dim text As String =  data.GetData(DataFormats.Text).ToString() 
Console.WriteLine(text)
 
'Close doc and shutdown Word application.
doc.Close( Nothingobj,  Nothingobj,  Nothingobj)
app.Quit( Nothingobj,  Nothingobj,  Nothingobj)
 
the dsoframer.ocx that's used to read/write office files should have a read method for word files that you can use to assign to the richtextbox

also to save the file again you'd just use the Save method that's provided
 
Back
Top