Advertisement

05.30.2008 at 02:41AM PDT, ID: 23444038
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

Save E-mail in Sent Folkder Excel VBA

Asked by KapTheHat in VB Script, Microsoft Excel Spreadsheet Software

Tags:

Thanks to the kind efforts of EE I have managed automate the generation of e-mails - with attachments. However I am unable to save the e-mails in the sent folder. A copy of the code used is given below. Start Free Trial
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:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
Sub Generate_Email(Email_SendTo As String, Email_Subject As String, EmailCCTo As String, EmailAtt As String, SaveOnSend As Boolean)
 
Dim EmailBCCTo
 
Dim objNotesSession As Object
Dim objNotesMailFile As Object
Dim ObjNotesDocument As Object
Dim objNotesField As Object
Dim RichTextAttachment As Object
Dim NotesAttach As Object
    
Dim SendMail As Boolean
 
On Error GoTo SendMailError
 
 
EmailBCCTo = "" ''Optional
 
''Establish Connection to Notes
 
Set objNotesSession = CreateObject("Notes.NotesSession")
 
'Establish Connection to Mail File
'.GetDatabase("SERVER","FILE")
 
Set objNotesMailFile = objNotesSession.GetDatabase("", "")
'Open Mail
 
objNotesMailFile.OpenMail
 
''Create New Memo
 
Set ObjNotesDocument = objNotesMailFile.CreateDocument
 
''Create 'Subject Field'
Set objNotesField = ObjNotesDocument.APPENDITEMVALUE("Subject", Email_Subject)
 
''Create 'Send To' Field
Set objNotesField = ObjNotesDocument.APPENDITEMVALUE("SendTo", Email_SendTo)
 
 
''Create 'Copy To' Field
 
Set objNotesField = ObjNotesDocument.APPENDITEMVALUE("CopyTo", EmailCCTo)
 
''Create 'Blind Copy To' Field
Set objNotesField = ObjNotesDocument.APPENDITEMVALUE("BlindCopyTo", EmailBCCTo)
 
''Create 'Body' of memo
Set objNotesField = ObjNotesDocument.CREATERICHTEXTITEM("Body")
 
With objNotesField
  .APPENDTEXT "This e-mail is generated by an automated process."
  .ADDNEWLINE 1
  .APPENDTEXT "Please follow established contact procedures should you have any questions"
  .ADDNEWLINE 2
End With
 
  
  
 
  Call objNotesField.EmbedObject(EMBED_ATTACHMENT, "", EmailAtt)
 
 
 'Save a copy of the e-mail in the sent folder
 
 
 objNotesField.SAVEMESSAGEONSEND = SaveOnSend
 Call objNotesField.ReplaceItemValue("PostedDate", Now())
 
 ''Send the e-mail
 
    
  ObjNotesDocument.Send (0)
  
  
 
 ''Release storage
 Set objNotesSession = Nothing
 Set objNotesMailFile = Nothing
 Set ObjNotesDocument = Nothing
 Set objNotesField = Nothing
 
 ''Set return code
 SendMail = True
 
Exit Sub
 
 
SendMailError:
Dim Msg
SendMail = False
 
 
End Sub
 
 
 
 
 
Sub Create_Email()
 
Dim Mail_Address As String
Dim Mail_Text As String
Dim Mail_CC As String
Dim Mail_Attach As String
 
Dim Loop_Counter As Integer
 
 
'Now Loop through all the records
'And Only E-mail those PCTS that we have e-mail addresses for
 
 
For Loop_Counter = 0 To Last_Formulae_Line
 
If Worksheets("Check").Range("First_EMail_Flag").Offset(Loop_Counter) = "YES" Then
 
 'Get the mail address
 
 Mail_Address = Worksheets("Check").Range("First_EMail_Address").Offset(Loop_Counter)
 
 'Get the mail text
 
 Mail_Text = Worksheets("Check").Range("First_Mail_Text").Offset(Loop_Counter)
 
 'Get the mail cc address
 
 Mail_CC = Worksheets("Check").Range("First_CC_Address").Offset(Loop_Counter)
 
 'Get the attachment
 
 Mail_Attach = Worksheets("Check").Range("First_Attach").Offset(Loop_Counter)
 
 
 
 Call Generate_Email(Mail_Address, Mail_Text, Mail_CC, Mail_Attach, True)
 
 
 'Update the flag stating that the e-mail has been sent
 
End If
 
 
 
Next Loop_Counter
[+][-]05.30.2008 at 02:51AM PDT, ID: 21676361

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.30.2008 at 11:42AM PDT, ID: 21680358

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.30.2008 at 12:14PM PDT, ID: 21680616

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: VB Script, Microsoft Excel Spreadsheet Software
Tags: Excel VBA
Sign Up Now!
Solution Provided By: chris_bottomley
Participating Experts: 1
Solution Grade: C
 
 
[+][-]07.13.2008 at 10:57PM PDT, ID: 21995961

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628