Click to See Complete Forum and Search --> : Open Word DOC into RTF Text Field?


AnkewDude
July 3rd, 2001, 04:06 PM
hey,

how do i open a word doc into an RTF Text Field, the way MS Word does it... i have already used Word Object and OLE.. they work but they aint good enuff...

Anybody knows how???

thanx...

Ankew.

Iouri
July 5th, 2001, 07:55 AM
Private Sub Command2_Click()'read
Set WordApp = CreateObject("Word.Application")
Set Document = Word.Documents.Add
Word.Documents.Open App.Path & "\TEST.DOC"
RichTextBox1.Text = Word.ActiveDocument.Range
'Word.Documents.Open
Word.Application.Quit
' Release the object variable
Set WordApp = Nothing
End Sub


Iouri Boutchkine
iouri@hotsheet.com

AnkewDude
July 5th, 2001, 12:28 PM
Thanx...

But i have already tried this... this doesnt help me.. cuz in case the Doc has a macro in it.. the machine hangs 5 out of 10 times n then the Winword in memory still remains which further creates truble..

but thanx fer the effort...

deghost
July 6th, 2001, 05:09 PM
i've tried playing with it and got to this:
you can open a word document using the richtextbox (97, idk about 2000) custom fileopen but i couldn't get the same results using the parameters offered manually from the app. anyway i'm sure it could be done. try it, if that's so use:
rtb.SaveFile "C:\filename.rtf", rtfRTF
after yo've manually chosen the path (or play with it until you get the same results)

----------
The @host is everywhere!
----------

AnkewDude
July 6th, 2001, 08:21 PM
hey...

u kindda make sense but i didnt really get whut u wrote.. cud u please explain..

thanx a ton fer the effort!

deghost
July 7th, 2001, 02:04 PM
SORRY, sorry, sorry...
I thaught i've opened .doc files but they were actually .rtf files (the icon is the same) and i didn't notice it because i had files with the same name in .doc & .rtf

maybe there are some simple .doc readers activeX controls that can easily be used. look them up

----------
The @host is everywhere!
----------

AnkewDude
July 8th, 2001, 09:09 AM
Hey..

Wud u know where i cud find an ActiveX control to open Doc files directly... i have searched fer it but really cudnt find sumthing yet...

thnx fer ure time

Ankew.

deghost
July 8th, 2001, 03:55 PM
sorry, kudn't find any 8,(

----------
The @host is everywhere!
----------

tomash
August 14th, 2001, 08:58 AM
Hi

I need to translate a TXT file to RTF - I can do it using Word.basic,... but:
Does anybody know how to do this on a PC without Word installed?
I can't get the Wordpad.Document to do the trick!??!?!?

Regards,
Thomas Eskesen

John G Duffy
August 14th, 2001, 10:07 AM
THis is a simple VB program that reads a .TXT file into a RichTextBOx and saves it as a .RTF file.
Start a new project. Add a RichTextBox to the form. Add two command buttons. Add this code to the forms General Declarations section of the form.
Modify the filenames and paths for the file in question. Run the program. Click Command1 to read the file. Click command2 to write the file as a .RTF file.

Dim strFileName as string
private Sub Command1_Click()
RichTextBox1.LoadFile strFileName & ".TXT", rtfText
End Sub
'
private Sub Command2_Click()
RichTextBox1.SaveFile strFileName & ".RTF", rtfRTF
End Sub
'
private Sub Form_Load()
strFileName = "C:\VB Stuff\VB Doc\InboxHelp"
End Sub
'




John G

tomash
August 14th, 2001, 10:48 AM
Hi

I have tried the
RichTextBox2.LoadFile "c:\temp\test.txt", rtfText
RichTextBox2.SaveFile "c:\temp\test.rtf", rtfRTF

But it doesnt work with my japanese txt file....

deghost
August 14th, 2001, 02:50 PM
is there some control that does read Japanese?

----------
The @host is everywhere!
----------

tomash
August 15th, 2001, 01:32 AM
Hi

How do I then convert my txt file to rtf - when it's in e.g. Japanese!??!?
(without having to installe Word)

Regrads,
Thomas Eskesen

ASDBob
October 29th, 2001, 03:38 AM
I may have a solution but it is not quite finished yet. I wanted to extract the text from a word document, and have written this function:


public Function GetTextFromWord(filepath as string)
Dim FileNum as Integer
Dim doctext as string
FileNum = FreeFile 'get file number
Open filepath for binary as #FileNum ' Open file just created.
doctext = input(filelen(filepath), #FileNum) ' get text from file
doctext = mid(doctext, 1281) 'strip header
doctext = Left(doctext, InStr(1, doctext, Chr(0)) - 2) 'strip formatting
doctext = Replace(doctext, Chr(13) & Chr(10), Chr(13)) ' hide correct CrLf
doctext = Replace(doctext, Chr(13), Chr(13) & Chr(10)) ' Correct Incorrect CrLf
doctext = Replace(doctext, Chr(7), " ") 'Remove funny charactors
doctext = Replace(doctext, Chr(9), " ") 'fix tabs
doctext = Replace(doctext, Chr(12), "")
Close #FileNum 'finished with file
GetTextFromWord = doctext 'return text
End Function



This is a very roughly coded solution and is not 100% reliable, the word header varies in size, documents sometimes contain bizzare formatting, embedded pictures, macros etc. Any further ideas on this would be greatly appreciated. I hope this helps