How to code an email link?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In VBA, how would I get to code an email link that gets activated when a
shape is clicked on? I'd also need to enter a subject to the email.

Thanks for your help!
 
In VBA, how would I get to code an email link that gets activated when a
shape is clicked on? I'd also need to enter a subject to the email.

Select the shape you want
Right click it
Choose Hyperlink
In the left of the dialog box choose Email Address
Type the email address and subject in the boxes provided.

If you have a version of PPT that doesn't do this, insert a hyperlink and type
as the address:

mailto:[email protected]?subject=This%20is%20th%20subject

Substitute the email address you want
Spaces in the subject should be replaced with %20

Understand that this won't necessarily work on all systems
 
Gaetan said:
Select the shape you want
Right click it
Choose Hyperlink
In the left of the dialog box choose Email Address
Type the email address and subject in the boxes provided.

If you have a version of PPT that doesn't do this, insert a hyperlink and type
as the address:

mailto:[email protected]?subject=This%20is%20th%20subject

Substitute the email address you want
Spaces in the subject should be replaced with %20

Understand that this won't necessarily work on all systems

I have this on other shapes of my presentation but the problem is that I
need to apply a macro that does something else to that specific shape, aside
from triggering an email. Anyway I can do both? Is there a way to code this
email in VBA?

Thanks Steve!
 
I have this on other shapes of my presentation but the problem is that I
need to apply a macro that does something else to that specific shape, aside
from triggering an email. Anyway I can do both? Is there a way to code this
email in VBA?


There's a slightly sneaky way of doing this.

Add another shape to the first slide in the show, name it something useful ...
let's say "Mailer" and assign it the hyperlink action needed to send mail. Then in
your macro you can do:

' Do other stuff here as you wish ...

' then tell PPT to follow the hyperlink on the Mailer shape:
With ActivePresentation.Slides(1).Shapes("Mailer")
.ActionSettings(pMouseClick).Hyperlink.Follow
End With
 
To take another turn from what Steve has suggested, if you are trying to
automate an email being sent you have to consider that not all email
programs are created the same. If you want to automate Outlook it takes
certain code, Lotus Notes, different code, etc.

Below is some sample code I use in my CBT program within PowerPoint that
sends a message. Keep in mind that automating Outlook poses its own
problem. Outlook wants to make sure you are wanting to do this and not
trying some spam stuff so you will get messages that need clicking through
for this to work. If nothing else, here is some free code to play with:

'====code starts here====

Sub EmailIt()
Dim objOutlook As Object 'Outlook.Application
Dim objOutlookMsg As Object 'Outlook.MailItem
Dim objOutlookRecip As Object 'Outlook.Recipient

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(0)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("put address here")
objOutlookRecip.Type = 1

' Set the Subject and Body of the message; save and send message
.Subject = "put subject text here" ' this could be from a variable if
you have one
.Body = "put body text here" ' this could be from a variable if you have
one
.Save
.Send
End With
Set objOutlook = Nothing

End Sub
'====code stops here====
 
Thank you Steve!

This does the job perfectly!
There's a slightly sneaky way of doing this.

Add another shape to the first slide in the show, name it something useful ...
let's say "Mailer" and assign it the hyperlink action needed to send mail. Then in
your macro you can do:

' Do other stuff here as you wish ...

' then tell PPT to follow the hyperlink on the Mailer shape:
With ActivePresentation.Slides(1).Shapes("Mailer")
.ActionSettings(pMouseClick).Hyperlink.Follow
End With

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 
We are working with Lotus. Steve's solution does exactly what I needed. But
I'll definatly keep note of your code if ever I need to do something similar
with Outlook. Your code seems to go a bit further too by actually entering
text in the body and sending itself. Might be useful.

Thanks Bill!
 
Well you're in luck. I have the code for Lotus Notes as well (something
like Version 5 or 6). Haven't had to use it in awhile so... Change the
email address below to your own and assign this to a button on your slide
and try it out. If Lotus Notes is not open it will open, ask you for your
password, and send the message.

'=====code starts here=====

Sub MailData()

Dim Session As Object, DB As Object, Memo As Object
Dim Server$, Mailfile$
Dim Item As Object

Set Session = CreateObject("Notes.NotesSession")

' Read the current mail server from Notes.ini
Server$ = Session.GETENVIRONMENTSTRING("MailServer", True)

' Read the current mail file from Notes.ini
Mailfile$ = Session.GETENVIRONMENTSTRING("MailFile", True)

' Try to open the mail database
Set DB = Session.GETDATABASE(Server$, Mailfile$)

' If Mail db not accessible, return an error
If Not DB.IsOpen Then
MsgBox "Could not access Notes mail file! Please contact - your name here."
Exit Sub
End If

'LN Message
'Create a memo in the user's mail file
Set Memo = DB.CREATEDOCUMENT

'Set the form to be a mail memo
Memo.Form = "Memo"
Memo.copyto = "wherever"

'Set the "from" field (not necessary)
Memo.From = Session.UserName

'Set the recipient of the memo
Memo.SendTo = "your email address here"

'Give the memo a subject
Memo.Subject = "put your subject here"

'Give the memo a body message
Memo.Body = "put body of message here"

'Send the memo
Call Memo.SEND(False, False)

' Restore NOTES variables back to nothing
Set DB = Nothing
Set Session = Nothing

End Sub

'=====code stops here=====
 
Back
Top