Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Mailto: Body= question

Status
Not open for further replies.

cyclesimon

Technical User
Aug 27, 2008
3
CA
This is a question further along the lines of the closed thread705-1438489.

I have the following code in an Excel module to open an e-mail with the address, subject and salutation automatically populated.

However, when the e-mail opens, the cursor position is in the upper LH corner of the mesaage body, i.e. to the left of the salutation, even though the %0a inserts a CrLf and puts the AAAA text on a new line.

How would I control the cursor position so that it is in the appropriate place to start adding the e-mail message?

Thanks all from a newbie.

Code:
Sub callmail()

Dim emaddr As String
Dim subj As String
Dim Name As String
Dim salutation As String

emaddr = Sheets("Sheet1").Range("A2")
subj = Sheets("Sheet1").Range("A3")
Name = Sheets("Sheet1").Range("A4")
salutation = Sheets("Sheet1").Range("A5")
'compose default parts of the message

hlink = "mailto:" & emaddr & "?"
hlink = hlink & "subject=" & subj & Name & " Producer Questionnaire Inquiry " & "&"
hlink = hlink & "body=" & salutation & "%0a" & "AAAA"
'open email

ActiveWorkbook.FollowHyperlink hlink

End Sub
 
I'm not sure it would work, but you might try something like this:
Code:
Me!txtControl.SelStart = 32000
Perhaps someone else has a better way.
 
AHJ1,

thanks, but I'm not sure where to add that - in Excel or Outlook (which is where I'm trying to set the cursor location.
 
Good To See Someone Reading My Old Posts!

PHV
Are you out there? Is there a HEX equaling of <CTRL-END>
 
Here's a possible workaround, if you like the idea. Using Ole Automation:

1. Write a line of text like @@@
2. Search for that line of text
3. Delete that text
4. Your cursor is properly positioned.

Maybe it's not elegant, but it will probably work.

Perhaps someone else can come up with a better suggestion.

Alan
 
Thanks to both AHJ1 and Pwise for putting their minds to this.

I haven't tried to implement either suggestion yet, but the question that come to mind right away is how would either strategy be implemented as part of the mailto: hyperlink.

It seems to me that either proposed action would have to be implemented once already in the mail application.

Am I on the right track here?

Newbie.
 
I am sorry. I tried several things but can't seem to get them to work. Here are three thoughts. I hope that you can work with them.

1. Try using Word as your editor. If this works, the first commented out piece of code should take you to the end of the document, which is being used to prepare your email.

2. Try using the SendKeys command. Unfortunately, I can't get it to work

3. The Outlook Developer Newsgroup might be able to help you with Outlook Object Model questions.


Again, I'm sorry. This is the best that I can do with the time constraints that I'm working under. Perhaps it will trigger an idea in someone.

Code:
Dim emaddr As String
Dim subj As String
Dim Name As String
Dim salutation As String
Dim hlink As Variant

emaddr = Sheets("Sheet1").Range("A2")
subj = Sheets("Sheet1").Range("A3")
Name = Sheets("Sheet1").Range("A4")
salutation = Sheets("Sheet1").Range("A5")
'compose default parts of the message

hlink = "mailto:" & emaddr & "?"
hlink = hlink & "subject=" & subj & Name & " Producer Questionnaire Inquiry " & "&"
hlink = hlink & "body=" & salutation & "%0a" & "AAAA"
'open email

ActiveWorkbook.FollowHyperlink hlink
'Selection.EndKey Unit:=wdStory
'SendKeys "{CTRL}+{End}"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top