Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,896
    Thanks
    0
    Thanked 86 Times in 82 Posts

    Re: RichTextBox (VB6)

    In case you haven't already seen it, this is the official MS way!
    Regards,
    Rory
    Microsoft MVP - Excel.

  2. #17
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RichTextBox (VB6)

    Excellent Find.

    This is my code:

    [s]Private Sub cmdClaimFom_Click()
    On Error GoTo ErrHandler
    Dim oWord As Object
    Dim oDoc As Object
    Dim strPath As String
    '================================================= ============================
    'sRTF represents the rich text formatted string to paste into Word
    Dim sRTF As String
    sRTF = "{rtf1ansiansicpg1252deff0deftab720{fonttbl" & _
    "{f0fswiss MS Sans Serif;}{f1fromanfcharset2 Symbol;}" & _
    "{f2fromanfprq2 Times New Roman;}}" & _
    "{colortblred0green0blue0;red255green0blue0;}" & _
    "deflang1033horzdoc{*fchars }{*lchars }" & _
    "pardplainf2fs24 Line 1 of plainf2fs24cf1" & _
    "insertedplainf2fs24 file.par }"

    'Copy the contents of the Rich Text to the clipboard
    Dim lSuccess As Long
    Dim lRTF As Long
    Dim hGlobal As Long
    Dim lpString As Long
    lSuccess = OpenClipboard(Me.hwnd)
    lRTF = RegisterClipboardFormat("Rich Text Format")
    lSuccess = EmptyClipboard
    hGlobal = GlobalAlloc(GMEM_MOVEABLE Or GMEM_DDESHARE, Len(sRTF))
    lpString = GlobalLock(hGlobal)

    CopyMemory lpString, ByVal sRTF, Len(sRTF)
    GlobalUnlock hGlobal
    SetClipboardData lRTF, hGlobal
    CloseClipboard
    GlobalFree hGlobal
    '================================================= ============================

    'Input Boxes
    Dim strPart As String
    strPart = InputBox("Part Description", "What Part Is This ?")

    Dim strMan As String
    strMan = InputBox("Please Enter A Vehicle Manufacturer", "What Make Of Car Is This ?")

    Dim strMod As String
    strMod = InputBox("What Model Is This ?", "Reported Fault")

    Dim strFault As String
    strFault = InputBox("What Kind Of Fault Is This ?", "Reported Fault")

    Dim strWin As String
    strWin = InputBox("Please Enter A Valid WIN No", "Internal Invoice No:")

    strPath = "C:Program FilesOrlandoSel Imperial Parts CatalogueSEL-DocsClaimForm1.doc"

    Set oWord = CreateObject("word.application")
    Set oDoc = oWord.documents.Add("C:Program FilesOrlandoSel Imperial Parts CatalogueSEL-DocsClaimForm.doc")

    frmWait.Show

    With oWord.Selection.Find

    .Execute FindText:="#PN#", ReplaceWith:=Me.txtPartNo.Text, Replace:=2
    .Execute FindText:="#rptDate#", ReplaceWith:=Date, Replace:=2
    .Execute FindText:="#strPart#", ReplaceWith:=strPart, Replace:=2
    .Execute FindText:="#strMan#", ReplaceWith:=strMan, Replace:=2
    .Execute FindText:="#strFault#", ReplaceWith:=strFault, Replace:=2
    .Execute FindText:="#strWin#", ReplaceWith:=strWin, Replace:=2
    .Execute FindText:="#strMod#", ReplaceWith:=strMod, Replace:=2
    .Execute FindText:="#Picture#"
    oWord.Selection.InlineShapes.AddPicture FileName:=Me.txtImgPath
    .Execute FindText:="#INDcomment#"
    oWord.Selection.Paste

    End With

    oDoc.SaveAs "C:Program FilesOrlandoSel Imperial Parts CatalogueSEL-DocsClaimForm1.doc"
    oDoc.Close False
    Set oDoc = Nothing
    oWord.NormalTemplate.Saved = True
    oWord.quit
    Set oWord = Nothing
    Unload frmWait

    MAPISession1.SignOn
    With MAPIMessages1
    .SessionID = MAPISession1.SessionID
    .Compose
    .MsgSubject = "Claim Form "
    .MsgNoteText = "Official SEL Claim Form"
    .AttachmentPathName = strPath
    .Send True
    End With
    exitHandler:
    On Error Resume Next
    MAPISession1.SignOff
    Exit Sub

    ErrHandler:
    If Err.Number = 32001 Then
    Resume Next
    End If
    Resume exitHandler

    End Sub[/s]

    Which produced this:
    How close am I ?

  3. #18
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RichTextBox (VB6)

    Thanks all, looks like this is it:

    <pre>sRTF = Me.RichTextBox1.TextRTF</pre>


  4. #19
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,896
    Thanks
    0
    Thanked 86 Times in 82 Posts

    Re: RichTextBox (VB6)

    You need to assign the RichTextBox's TextRTF property to the variable sRTF (i.e. replace the current
    <code>sRTF = "{rtf1</code>...
    with
    <code>sRTF = me.txtWhateverItsCalled.TextRTF</code>)
    Regards,
    Rory
    Microsoft MVP - Excel.

Page 2 of 2 FirstFirst 12

Posting Permissions

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