Inserting text from another file into a point in a RichText control

Posted on 2005-03-10
Medium Priority
Last Modified: 2010-05-02
I would like to be able to position the cursor at a certain point and then by right clicking choose "insert" and open a file and copy its contents into the RTF control at that point.
Question by:garyLittle
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 32

Accepted Solution

Erick37 earned 1000 total points
ID: 13507371
Following assumes:
CommonDialog control: cdlg
Richtextbox control: RichTextBox1
Menu Items for the popup menu: mnuPop->mnuInsert

Option Explicit

Private Sub mnuInsert_Click()
    On Error GoTo ERR_CANCEL
    Dim sInsert As String
    'CommonDialog control named cdlg
    cdlg.CancelError = True
    cdlg.Filter = "Text (*.txt)|*.txt"
    cdlg.Flags = cdlOFNFileMustExist
    cdlg.InitDir = "c:\"
    Open cdlg.FileName For Binary As #1
    'make room for the contents
    sInsert = Space(LOF(1))
    'get the data
    Get #1, , sInsert
    Close #1
    'paste the contents
    RichTextBox1.SelText = sInsert
    Exit Sub
End Sub

Private Sub RichTextBox1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = vbRightButton Then
        PopupMenu mnuPop
    End If
End Sub

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question