#1
|
|||
|
|||
Place Cursor in multiline HTML Body
Hi all. I am using the below code to generate an html email with the default signature in outlook. The output is great; however, the cursor does not appear until I tab or click in a field other than the body and then tab/click back into the body. I would like the cursor to appear two lines below the salutation. Any ideas on how to place the cursor, preferably without using sendkeys?
Code:
Private Sub EmailBtnUnits2020_Click() Dim OutApp As Object Dim OutMail As Object Dim StrBody As String Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) StrBody = "<html><body><font size=""3"" face=""Calibri"" color=""black""><p>Hi " & ActiveSheet.Range("W4").Text & ",</p>" _ & "</font></body></html>" On Error Resume Next With OutMail .Display .To = ActiveSheet.Range("AC4").Text .CC = "" .BCC = "" .Subject = "Question" .HTMLbody = StrBody & "<br>" & .HTMLbody .Display End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End Sub |
#2
|
|||
|
|||
mind if I ask why you don't want to use
Code:
SendKeys "{TAB}{TAB}{TAB}{END}{ENTER}{ENTER}", True |
#3
|
|||
|
|||
I was using that, but I sometimes get a funny result with extra tabs prior to the salutation, even when I delay it.
|
#4
|
|||
|
|||
Your macro finishes with the cursor in the To: text box
The number of tabs required will depend on what you have visible. I don't display Bcc so first tab is out of To and into Cc, second tab out of Cc and into Subject, third tab out of Subject and into the Body. |
#5
|
|||
|
|||
Hmm this will be run on about 20 machines. I suppose we are all running the same version of office (365), so I imagine most or all will have the same fields visible. I can use sendkeys for now--it just seemed inconsistent when I had it set up, so I was hoping for something more controlled. Maybe I can try for a longer delay.
|
#6
|
||||
|
||||
Just in passing, this is really an Outlook programming question, not Excel. But I'm not complaining; I've posted questions about VBA/Outlook over at that forum and never gotten an answer; you're much more likely to get some useful response here.
I share your distaste for SendKeys, if for no other reason than that different users will have different options running. Doesn't matter whether you're all using the same version of Outlook; some users (including myself) always add the bcc box first thing when they are force-fed a new version of Outlook, others never do, so counting {Tab}s won't do it for you. Placing the cursor within an HTML email body would normally be complicated by the fact that different users have different signatures, default fonts etc. But if you're going to define the entire body, allowing no variation in the HTML tags as well as the textual content, maybe that part won't be a problem. In that case, assuming every user will be using the Word email editor, you should be able to set the cursor position using a VBA/Word method or property. I haven't done it in long enough that I'd have to research it from scratch, but I have had to do it so I know it can be done. If you can figure it out from that minuscule hint, great; otherwise complain a little more and I'll see what I can dig up. |
#7
|
|||
|
|||
Thanks Bob. That gives me something to play with this week. I'll see what I can come up with.
|
Tags |
cursor, email, multiple lines |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Pasted pictures go all over the place, not at the cursor | WaltR | Word | 9 | 09-20-2013 05:58 PM |
Can't Place Cursor to Insert Subdocument | ForWork | Word | 4 | 03-08-2013 03:10 AM |
Place cursor below msg body in reply | charles.h | Outlook | 0 | 10-03-2009 03:05 AM |
Replying to a message and having the cursor go into the body | join_the_band | Outlook | 1 | 12-02-2005 06:21 AM |
HTML Format Body - Scripts? | jeffcravener | Outlook | 0 | 11-14-2005 10:58 AM |