Hi,
I am trying to receive email notifications when someone opens power point deck. I can do it in excel without having any issue however in power point I cant auto execute the code when .ppt file opens. I can manually run it and it works but need it to auto execute.
I am using below code, did anyone come across similar issue before?
I am trying to receive email notifications when someone opens power point deck. I can do it in excel without having any issue however in power point I cant auto execute the code when .ppt file opens. I can manually run it and it works but need it to auto execute.
I am using below code, did anyone come across similar issue before?
Code:
Public Sub Auto_Open()
Dim oApp As Object
Dim ns As Object
Dim fldr As Object
Dim mItem As Object
Dim sendTo As Object
Dim bOutlookFound As Boolean
Dim FileOnly As String
FileOnly = ActivePresentation.Name
On Error Resume Next
Set oApp = GetObject(, "Outlook.Application")
bOutlookFound = Err.Number = 0
On Error GoTo 0
If Not bOutlookFound Then Set oApp = CreateObject("Outlook.Application")
Set ns = oApp.GetNamespace("MAPI")
Set fldr = ns.GetDefaultFolder(6)
'# create an outlook MailItem:
Set mItem = oApp.CreateItem(0) 'olMailItem
'# assign a recipient
Set sendTo = mItem.Recipients.Add("lauren.chapel@hotmail.com")
sendTo.Type = 1 'To olTo
For Each sendTo In mItem.Recipients
sendTo.Resolve
Next
mItem.Subject = "A user has opened the .ppt file"
mItem.Body = "This is an automated message to inform you that " & _
Environ("username") & " has downloaded and is using " & _
FileOnly
mItem.Save
mItem.Send
'If outlook was not already open, then quit
If Not bOutlookFound Then oApp.Quit
Set oApp = Nothing
End Sub