Results 1 to 8 of 8

Thread: Rich Text Box GURU Question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    Atlanta, GA
    Posts
    177

    Angry Rich Text Box GURU Question

    Hello,

    1) Does anyone know how to load a word file into a rich text box?
    2) Does anyone know how to convert a word document to a Rich Text File type using VB Coding? thanks in advance.
    212 will lead you to the truth

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    2) I found this out by creating a Word macro as I did it.

    ActiveDocument.SaveAs FileName:="Doc1.rtf", FileFormat:=wdFormatRTF, _
    LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
    :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
    SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
    False

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    to expand on martin's code:

    you have to pen the file first in word:
    VB Code:
    1. Dim OBJ as Object
    2. Set OBJ = CreateObject("word.application")
    3. OBJ.Documents.Open FileName:="[b]C:\PATH\FILENAME.Doc[/b]", _
    4. ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
    5. PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
    6. WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
    7. wdOpenFormatAuto
    8. OBJ.ActiveDocument.SaveAs FileName:="[b]C:\PATH\FILENAME.RTF[/b]", ", FileFormat _
    9. :=wdFormatRTF, LockComments:=False, Password:="", AddToRecentFiles:=True _
    10. , WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
    11. False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
    12. SaveAsAOCELetter:=False
    13.  
    14. 'then your code to open the file
    15. 'I think its
    16. RichTextBox.File = "C:\PATH\FILE.rtf"
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    Atlanta, GA
    Posts
    177
    First off thanks for the help. where are the breaks? is this using an object?
    212 will lead you to the truth

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    Atlanta, GA
    Posts
    177
    Thanks let me see if I can get this to work.
    212 will lead you to the truth

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    Atlanta, GA
    Posts
    177
    Is all of this coding neccessary? Will the following work?OBJ.Documents.Open FileName:=wfilename

    OBJ.ActiveDocument.SaveAs FileName:=ConvertedName

    I was getting an error somewhere in the orginal string.
    212 will lead you to the truth

  7. #7
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    sorry...change
    wdFormatRTF to 6

    or add in the gen dec section
    Private Const wdFormatRTF = 6

    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    Atlanta, GA
    Posts
    177
    The code is still failing on the section that opens the doc.

    Here is what I have so far:
    'Gen dec
    Private wFileName As String
    Private Const wdFormatRTF = 6


    Private Sub Command2_Click()
    Dim OBJ As Object
    Dim docNew As Object
    Dim rtfDoc As Object
    Dim c
    Dim Txt$
    Dim ConvertedName As String

    CMDialog1.InitDir = App.Path
    CMDialog1.Filter = "Text Files|*.Txt|Rich Text Files|*.rtf|Word Document|*.doc|All Files|*.*"
    CMDialog1.FilterIndex = 3
    CMDialog1.Flags = 3
    CMDialog1.Action = 1
    If CMDialog1.FileName = "" Then
    Exit Sub
    End If
    wFileName = CMDialog1.FileName
    txtOriginalFileName.Text = wFileName
    '****************************************************


    Txt$ = wFileName


    For i = 1 To Len(Txt$)
    c = Mid$(Txt$, i, 1)
    If c = "." Then
    ConvertedName = ConvertedName + ".rtf"
    MsgBox ConvertedName
    Exit For
    Else
    ConvertedName = ConvertedName + c
    End If
    Next

    Set OBJ = CreateObject("word.application")

    'The error occurs in the section below
    OBJ.Documents.Open FileName:=wFileName, _
    ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
    PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
    WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
    wdOpenFormatAuto

    OBJ.ActiveDocument.SaveAs FileName:=ConvertedName, FileFormat _
    :=wdFormatRTF, LockComments:=False, Password:="", AddToRecentFiles:=True _
    , WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
    False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
    SaveAsAOCELetter:=False

    'then your code to open the file
    'I think its
    rtbDisplay.LoadFile (ConvertedName)

    End Sub
    212 will lead you to the truth

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