Consulting

Results 1 to 4 of 4

Thread: Insert symbol into text box - in the active textbox where the mouse cursor is located

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Insert symbol into text box - in the active textbox where the mouse cursor is located

    Insert symbol into text box - in the active textbox where the mouse cursor is located:

    I have code :

    =====================================================

    Private Sub CommandButton1_Click()
    Dim doClip As DataObject
    Dim bulletStr As String
    Set doClip = New DataObject
    bulletStr = "• "
    doClip.SetText bulletStr
    doClip.PutInClipboard
    With Me.TextBox1
    .Paste
    .SetFocus
    End With
    End Sub

    =====================================================

    An I have 5 textbox . VBA Code from above is work only for "TextBox1"....but if I select TextBox 2 ( or other ) and give click on button....also in my textbox1 inserts the symbol. I do not know how to do this process to see the textbox I've selected with the mouse, and to insert my symbol when I press the insert button.

    Can you help me with that ?

    Please, see my file in attach.

    Thank you in advance,

    BogdanInsert-Simbols-Copy.xlsb

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Welcome to the forum

    Take a minute to read the FAQs in my signature

    Try this


    Option Explicit
    Dim oTextbox As MSForms.TextBox
    
    Private Sub CommandButton1_Click()
        Dim doClip    As DataObject
        Dim bulletStr As String
        Set doClip = New DataObject
        bulletStr = "? "
        doClip.SetText bulletStr
        doClip.PutInClipboard
    
    '    With Me.TextBox1    '   <<<<<<<<<<<<<<<<<<<<<< what did you expect
        With oTextbox
            .Paste
            .SetFocus
        End With
    
    End Sub
    
    
    
    
    Private Sub TextBox1_Enter()
        Set oTextbox = TextBox1
    End Sub
    Private Sub TextBox2_Enter()
        Set oTextbox = TextBox2
    End Sub
    Private Sub TextBox3_Enter()
        Set oTextbox = TextBox3
    End Sub
    Private Sub TextBox4_Enter()
        Set oTextbox = TextBox4
    End Sub
    Private Sub TextBox5_Enter()
        Set oTextbox = TextBox5
    End Sub
    Private Sub TextBox6_Enter()
        Set oTextbox = TextBox6
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    If this is in a userform and if you set the .TakeFocusOnClick property of the CommandButton to False, you could use the userform's ActiveControl property to determine which Textbox has the focus.

  4. #4
    Thank you for your sugestion. You are most welcome!

    Bogdan

Posting Permissions

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