Question : Macro to email an attached Excel file on Lotus Notes email client

We use Lotus Notes as our emal client.

I would like a macro that will
- save an Excel file
- attach the file to an email
- email must be addressed to:  [email protected]; [email protected]
-subject line must state: Weekly Form

I have found the attached code on EE which works well.  It does the following:
- saves the file
-attaches the file to an email
-prompts you to enter recipient's email address
- prompts you to enter a message

Can someone pls modify it so that:
- my two recipients are hard-coded in the macro
- it does not prompt for a message to be entered

Thanks.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
Sub SendWithLotus() 
   Dim noSession As Object, noDatabase As Object, noDocument As Object 
   Dim obAttachment As Object, EmbedObject As Object 
   Dim stSubject As Variant, stAttachment As String 
   Dim vaRecipient As Variant, vaMsg As Variant 
 
 
   Const EMBED_ATTACHMENT As Long = 1454 
   Const stTitle As String = "Status Active workbook" 
   Const stMsg As String = "The active workbook must first be saved " & vbCrLf _ 
         & "before it can be sent as an attachment." 
 
   'Check if the active workbook is saved or not 
   'If the active workbook has not been saved at all. 
   If Len(ActiveWorkbook.Path) = 0 Then 
      MsgBox stMsg, vbInformation, stTitle 
      Exit Sub 
   End If 
 
   'If the changes in the active workbook has been saved or not. 
   If ActiveWorkbook.Saved = False Then 
      If MsgBox("Do you want to save the changes before sending?", _ 
            vbYesNo + vbInformation, stTitle) = vbYes Then _ 
            ActiveWorkbook.Save 
   End If 
 
   'Get the name of the recipient from the user. 
   Do 
      vaRecipient = Application.InputBox( _ 
            Prompt:="Please add the name of the recipient such as:" & vbCrLf _ 
            & "[email protected] or just the name if it's internally.", _ 
            Title:="Recipient", Type:=2) 
   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:="Please enter the message such as:" & vbCrLf _ 
            & "Enclosed please find the weekly report.", _ 
            Title:="Message", Type:=2) 
   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 = "Weekly report" 
 
   'Retrieve the path and filename of the active workbook. 
   stAttachment = ActiveWorkbook.FullName 
 
   'Instantiate the Lotus Notes COM's Objects. 
   Set noSession = CreateObject("Notes.NotesS ession") 
   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.CreateRichTextI tem("stAtt achment") 
   Set EmbedObject = obAttachment.EmbedObject(E MBED_ATTAC HMENT, "", stAttachment) 
 
 
   'Add values to the created e-mail main properties. 
   With noDocument 
      .Form = "Memo" 
      .SendTo = vaRecipient 
      .Subject = stSubject 
      .Body = vaMsg 
      .SaveMessageOnSend = True 
   End With 
 
   'Send the e-mail. 
   With noDocument 
      .PostedDate = Now() 
      .Send 0, vaRecipient 
   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 
 
End Sub
Open in New Window Select All

Answer : Macro to email an attached Excel file on Lotus Notes email client

Hi

I have modified the code to suit your need. Hope this helps

Cheers
P.K.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
Sub SendWithLotus()
   Dim noSession As Object, noDatabase As Object, noDocument As Object
   Dim obAttachment As Object, EmbedObject As Object
   Dim stSubject As Variant, stAttachment As String
   Dim vaRecipient As Variant, vaMsg As Variant
 
 
   Const EMBED_ATTACHMENT As Long = 1454
   Const stTitle As String = "Status Active workbook"
   Const stMsg As String = "The active workbook must first be saved " & vbCrLf _
         & "before it can be sent as an attachment."
 
   'Check if the active workbook is saved or not
   'If the active workbook has not been saved at all.
   If Len(ActiveWorkbook.Path) = 0 Then
      MsgBox stMsg, vbInformation, stTitle
      Exit Sub
   End If
 
   'If the changes in the active workbook has been saved or not.
   If ActiveWorkbook.Saved = False Then
      If MsgBox("Do you want to save the changes before sending?", _
            vbYesNo + vbInformation, stTitle) = vbYes Then _
            ActiveWorkbook.Save
   End If
 
   'Get the name of the recipient from the user.
      vaRecipient = "[email protected]; [email protected]"
 
   'If the user has canceled the operation.
   If vaRecipient = 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 = "Weekly Form"
 
   'Retrieve the path and filename of the active workbook.
   stAttachment = ActiveWorkbook.FullName
 
   'Instantiate the Lotus Notes COM's Objects.
   Set noSession = CreateObject("Notes.NotesS ession")
   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.CreateRichTextI tem("stAtt achment")
   Set EmbedObject = obAttachment.EmbedObject(E MBED_ATTAC HMENT, "", stAttachment)
 
 
   'Add values to the created e-mail main properties.
   With noDocument
      .Form = "Memo"
      .SendTo = vaRecipient
      .Subject = stSubject
      .Body = ""
      .SaveMessageOnSend = True
   End With
 
   'Send the e-mail.
   With noDocument
      .PostedDate = Now()
      .Send 0, vaRecipient
   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
 
End Sub
Open in New Window Select All
Random Solutions  
 
programming4us programming4us