Setting Focus of Cursor in Textbox in Between Specific Lines

JarekM

Board Regular
Joined
Nov 13, 2018
Messages
86
Hi,

I have a textbox where whenever I click to write an email, the cursor shows up below the word "regards", but I want the cursor to show up in between the words "regards" and "Dear Sir".

Here's a screenshot of the textbox:
tinypic.com
[/URL][/IMG]





Here is the code that I used as well:
Code:
_Subject = "Invoice: " + frmcustomer.lstCustomer.column(0) & " of " + frmcustomer.lstCustomer.column(4)
weiter:

    If cboTitleSalutation = "Mr" Then
        frmEmail.txt_EMessage.Value = "Dear Sir " & Me.txt_name & "," & vbLf & vbLf & vbLf & vbLf & "Regards " & vbLf & Sheets("Setup").Range("C55")
        frmEmail.txt_EMessage.SetFocus
    ElseIf cboTitleSalutation = "Mrs" Then
        frmEmail.txt_EMessage.Value = "Dear Mrs " & txt_name & "," & vbLf & vbLf
        frmEmail.txt_EMessage.SetFocus
    Else
        frmEmail.txt_EMessage.Value = "Dear Sir or Madam, " & vbLf & vbLf
        frmEmail.txt_EMessage.SetFocus
    End If

    frmEmail.txt_TO.Value = frmcustomer.txt_Email.Value
    frmEmail.Show
End Sub

Is there a way to fix this?
If so, then thanks.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try this.
Code:
Dim lngStartPos As Long


    If cboTitleSalutation = "Mr" Then
        frmEmail.txt_EMessage.Value = "Dear Sir " & Me.txt_name & "," & vbLf & vbLf & vbLf
    ElseIf cboTitleSalutation = "Mrs" Then
        frmEmail.txt_EMessage.Value = "Dear Mrs " & txt_name & "," & vbLf & vbLf
    Else
        frmEmail.txt_EMessage.Value = "Dear Sir or Madam, " & vbLf & vbLf
    End If


    lngStartPos = Len(frmEmail.txt_EMessage.Text)+1

    frmEmail.txt_EMessage.Value = frmEmail.txt_EMessage.Value & vbLf & vbLf & "Regards " & vbLf & Sheets("Setup").Range("C55")

    frmEmail.txt_EMessage.SetFocus

    frmemail.txt_EMessage.SelStart = lngStartPos
 
Last edited:
Upvote 0
Thanks for t help, but we are not quite there yet.

As you can see, in the screenshot below, you have managed to put the cursor in between the letters "g" and the "a" in "regards". I would like to have the cursor where the second arrow is pointing.

tinypic.com
[/URL][/IMG]

Thanks in advance.
 
Upvote 0
Try changing this,
Code:
    lngStartPos = Len(frmEmail.txt_EMessage.Text)+1
to this.
Code:
    lngStartPos = Len(frmEmail.txt_EMessage.Text)-3

If that doesn't work you'll probably need to keep playing about with incrementing/decrementing the value of lngStartPos to get it as you want it.
 
Upvote 0
Hi Norie,

Your code has solved the issue!
Thank you for helping me.

Kind regards,
Jarek.
 
Upvote 0

Forum statistics

Threads
1,212,933
Messages
6,110,752
Members
448,295
Latest member
Uzair Tahir Khan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top