Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-05-2020, 02:46 PM
PrincessApril PrincessApril is offline Place Cursor in multiline HTML Body Windows 10 Place Cursor in multiline HTML Body Office 2019
Competent Performer
Place Cursor in multiline HTML Body
 
Join Date: Nov 2019
Posts: 102
PrincessApril is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 03-06-2020, 09:52 AM
NoSparks NoSparks is offline Place Cursor in multiline HTML Body Windows 10 Place Cursor in multiline HTML Body Office 2010
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

mind if I ask why you don't want to use
Code:
SendKeys "{TAB}{TAB}{TAB}{END}{ENTER}{ENTER}", True
Reply With Quote
  #3  
Old 03-06-2020, 01:01 PM
PrincessApril PrincessApril is offline Place Cursor in multiline HTML Body Windows 10 Place Cursor in multiline HTML Body Office 2019
Competent Performer
Place Cursor in multiline HTML Body
 
Join Date: Nov 2019
Posts: 102
PrincessApril is on a distinguished road
Default

I was using that, but I sometimes get a funny result with extra tabs prior to the salutation, even when I delay it.
Reply With Quote
  #4  
Old 03-06-2020, 02:26 PM
NoSparks NoSparks is offline Place Cursor in multiline HTML Body Windows 10 Place Cursor in multiline HTML Body Office 2010
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

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.
Reply With Quote
  #5  
Old 03-06-2020, 08:03 PM
PrincessApril PrincessApril is offline Place Cursor in multiline HTML Body Windows 10 Place Cursor in multiline HTML Body Office 2019
Competent Performer
Place Cursor in multiline HTML Body
 
Join Date: Nov 2019
Posts: 102
PrincessApril is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 03-08-2020, 02:24 PM
BobBridges's Avatar
BobBridges BobBridges is offline Place Cursor in multiline HTML Body Windows 7 64bit Place Cursor in multiline HTML Body Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

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.
Reply With Quote
  #7  
Old 03-09-2020, 10:06 AM
PrincessApril PrincessApril is offline Place Cursor in multiline HTML Body Windows 10 Place Cursor in multiline HTML Body Office 2019
Competent Performer
Place Cursor in multiline HTML Body
 
Join Date: Nov 2019
Posts: 102
PrincessApril is on a distinguished road
Default

Thanks Bob. That gives me something to play with this week. I'll see what I can come up with.
Reply With Quote
Reply

Tags
cursor, email, multiple lines

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Place Cursor in multiline HTML Body 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:48 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft