Mikec1012
New Member
- Joined
- Oct 24, 2017
- Messages
- 30
Hello there!
I have pieced together several macros and I am almost good to go with my project. However, the macro I need help with is the actual sending the mail. The script I found, would generate a pop up and could use that to enter in an email address. However, I'd like to remove the pop up and have it reference a specific cell. At my job, we can send emails with a 5 digit employee ID number. So part of the macro is set to auto fill K2 with the EID (employee ID); however, not sure how to get the code to reference the cell.
Here's my code:
The following pertains to sending the email with attachment
'Get the name of the recipient from the user.
'Do
' vaRecipient = Application.InputBox( _
' PROMPT:=" *** Enter the EID you are sending the report to *** ")
' Loop While vaRecipient = ""
'If the user has canceled the operation.
'If vaRecipient = False Then Exit Sub
'Get the message from the user.
Do
vaMsg = Application.InputBox( _
PROMPT:="Who does the report belong to:")
Loop While vaMsg = ""
'If the user has canceled the operation.
If vaMsg = False Then Exit Sub
'Add the subject to the outgoing e-mail which also can be retrieved from the users
'in a similar way as above.
stSubject = vaMsg & ", here is your K08 Report for " & Format(Date, "mm/dd/yy")
'Retrieve the path and filename of the active workbook.
stAttachment = ActiveWorkbook.FullName
'Instantiate the Lotus Notes COM's Objects.
Set noSession = CreateObject("Notes.NotesSession")
Set noDatabase = noSession.GETDATABASE("", "")
'If Lotus Notes is not open then open the mail-part of it.
If noDatabase.IsOpen = False Then noDatabase.OPENMAIL
'Create the e-mail and the attachment.
Set noDocument = noDatabase.CREATEDOCUMENT
Set obAttachment = noDocument.CREATERICHTEXTITEM("stAttachment")
Set EmbedObject = obAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment)
'Add values to the created e-mail main properties.
With noDocument
.Form = "Memo"
.SendTo = Range("L2")
.Subject = stSubject
.Body = "Here is your K08 report " & vaMsg & "! Blood, sweat and tears went into compiling this for you. Jk! I clicked one button."
.SAVEMESSAGEONSEND = True
End With
'Send the e-mail.
' With noDocument
' .PostedDate = Now()
' .SEND 0, Range("K2")
' End With
'Release objects from the memory.
Set EmbedObject = Nothing
Set obAttachment = Nothing
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
'Activate Excel for the user.
AppActivate "Microsoft Excel"
MsgBox "The e-mail has successfully been created and distributed.", vbInformation
I have pieced together several macros and I am almost good to go with my project. However, the macro I need help with is the actual sending the mail. The script I found, would generate a pop up and could use that to enter in an email address. However, I'd like to remove the pop up and have it reference a specific cell. At my job, we can send emails with a 5 digit employee ID number. So part of the macro is set to auto fill K2 with the EID (employee ID); however, not sure how to get the code to reference the cell.
Here's my code:
The following pertains to sending the email with attachment
'Get the name of the recipient from the user.
'Do
' vaRecipient = Application.InputBox( _
' PROMPT:=" *** Enter the EID you are sending the report to *** ")
' Loop While vaRecipient = ""
'If the user has canceled the operation.
'If vaRecipient = False Then Exit Sub
'Get the message from the user.
Do
vaMsg = Application.InputBox( _
PROMPT:="Who does the report belong to:")
Loop While vaMsg = ""
'If the user has canceled the operation.
If vaMsg = False Then Exit Sub
'Add the subject to the outgoing e-mail which also can be retrieved from the users
'in a similar way as above.
stSubject = vaMsg & ", here is your K08 Report for " & Format(Date, "mm/dd/yy")
'Retrieve the path and filename of the active workbook.
stAttachment = ActiveWorkbook.FullName
'Instantiate the Lotus Notes COM's Objects.
Set noSession = CreateObject("Notes.NotesSession")
Set noDatabase = noSession.GETDATABASE("", "")
'If Lotus Notes is not open then open the mail-part of it.
If noDatabase.IsOpen = False Then noDatabase.OPENMAIL
'Create the e-mail and the attachment.
Set noDocument = noDatabase.CREATEDOCUMENT
Set obAttachment = noDocument.CREATERICHTEXTITEM("stAttachment")
Set EmbedObject = obAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment)
'Add values to the created e-mail main properties.
With noDocument
.Form = "Memo"
.SendTo = Range("L2")
.Subject = stSubject
.Body = "Here is your K08 report " & vaMsg & "! Blood, sweat and tears went into compiling this for you. Jk! I clicked one button."
.SAVEMESSAGEONSEND = True
End With
'Send the e-mail.
' With noDocument
' .PostedDate = Now()
' .SEND 0, Range("K2")
' End With
'Release objects from the memory.
Set EmbedObject = Nothing
Set obAttachment = Nothing
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
'Activate Excel for the user.
AppActivate "Microsoft Excel"
MsgBox "The e-mail has successfully been created and distributed.", vbInformation