CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Jul 2001
    Location
    Northern Hemisphere
    Posts
    14

    Open Word DOC into RTF Text Field?

    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.


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Open Word DOC into RTF Text Field?

    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
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Jul 2001
    Location
    Northern Hemisphere
    Posts
    14

    Re: Open Word DOC into RTF Text Field?

    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...


  4. #4
    Join Date
    Jun 2001
    Location
    Israel
    Posts
    228

    Re: Open Word DOC into RTF Text Field?

    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!
    ----------

  5. #5
    Join Date
    Jul 2001
    Location
    Northern Hemisphere
    Posts
    14

    Re: Open Word DOC into RTF Text Field?

    hey...

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

    thanx a ton fer the effort!


  6. #6
    Join Date
    Jun 2001
    Location
    Israel
    Posts
    228

    Re: Open Word DOC into RTF Text Field?

    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!
    ----------

  7. #7
    Join Date
    Jul 2001
    Location
    Northern Hemisphere
    Posts
    14

    Re: Open Word DOC into RTF Text Field?

    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.


  8. #8
    Join Date
    Jun 2001
    Location
    Israel
    Posts
    228

    Re: Open Word DOC into RTF Text Field?

    sorry, kudn't find any 8,(

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

  9. #9
    Join Date
    Aug 2001
    Posts
    3

    Re: Open Word DOC into RTF Text Field?

    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



  10. #10
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Open Word DOC into RTF Text Field?

    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

  11. #11
    Join Date
    Aug 2001
    Posts
    3

    Re: Open Word DOC into RTF Text Field?

    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....




  12. #12
    Join Date
    Jun 2001
    Location
    Israel
    Posts
    228

    Re: Open Word DOC into RTF Text Field?

    is there some control that does read Japanese?

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

  13. #13
    Join Date
    Aug 2001
    Posts
    3

    Re: Open Word DOC into RTF Text Field?

    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



  14. #14
    Join Date
    Oct 2001
    Posts
    1

    Re: Open Word DOC into RTF Text Field?

    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


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured