Andrew420
asked on
Sending emails with attachment …
Hi, I am using Excel 97 and I have Lotus Notes as my default email system. I am trying to send files through email with excel vba. I'd like to use a dialog for selecting multiple files to attach. I have not found any code without a default path so far. Thanks for your help.
also
https://www.experts-exchange.com/questions/21677209/Create-attachment-in-Notes-from-Excel-VBA.html
Once you put the file names into an Excel sheet, you can attach as shown :
See the sample code for more info:
Attach1 = Cells(10, 1)
Attach2 = Cells(10, 2)
'Attach a document!
Call rtItem.EmbedObject(EMBED_A TTACHMENT, "",Attach1 )
Call rtItem.EmbedObject(EMBED_A TTACHMENT, "",Attach2 )
Call doc.send (False)
https://www.experts-exchange.com/questions/21677209/Create-attachment-in-Notes-from-Excel-VBA.html
Once you put the file names into an Excel sheet, you can attach as shown :
See the sample code for more info:
Attach1 = Cells(10, 1)
Attach2 = Cells(10, 2)
'Attach a document!
Call rtItem.EmbedObject(EMBED_A
Call rtItem.EmbedObject(EMBED_A
Call doc.send (False)
IMHO, as it is an Excel-VBA question, this question is posted in the wrong TA. You could ask a Page Editor to move it.
Since similar questions have been resolved here, I see no reason to move it.
It does require a mix of Notes and VBA expertise.
Just my $0.02
It does require a mix of Notes and VBA expertise.
Just my $0.02
ASKER
As I couldn't open the links you've sent, I've posted my imperfect code below. Maybe there is a function in the same way like 'application.GetOpenFileNa me' in a way of 'create attachments' for selecting multiple files and embed the attachment ? (see below 'critical part')
Thanks a lot for your help!
Dim objNotesSession As Object
Dim objNotesMailFile As Object
Dim objNotesDocument As Object
Dim objNotesField As Object
Dim varRetVal As Variant
Dim n As Integer
Function SendMail()
On Error GoTo SendMailError
EMailSendTo = "test@test.com"
EMailCCTo = ""
EMailBCCTo = ""
EMailSubject = "test“
''Establish Connection to Notes
Set objNotesSession = CreateObject("Notes.NotesS ession")
''Establish Connection to Mail File
Set objNotesMailFile = objNotesSession.GETDATABAS E("", "")
''Open Mail
objNotesMailFile.OPENMAIL
''Create New Memo
Set objNotesDocument = objNotesMailFile.CREATEDOC UMENT
''Create 'Subject Field'
Set objNotesField = objNotesDocument.APPENDITE MVALUE("Su bject", EMailSubject)
''Create 'Send To' Field
Set objNotesField = objNotesDocument.APPENDITE MVALUE("Se ndTo", EMailSendTo)
''Create 'Copy To' Field
Set objNotesField = objNotesDocument.APPENDITE MVALUE("Co pyTo", EMailCCTo)
''Create 'Blind Copy To' Field
Set objNotesField = objNotesDocument.APPENDITE MVALUE("Bl indCopyTo" , EMailBCCTo)
''Create 'Body' of memo
Set objNotesField = objNotesDocument.CREATERIC HTEXTITEM( "Body")
With objNotesField
.APPENDTEXT "Text"
.ADDNEWLINE 1
.APPENDTEXT "Text2"
.ADDNEWLINE 2
End With
‘‘CRITICAL PART
''Open dialog for file selection
varRetVal = Application.GetOpenFileNam e( _
FileFilter:="Microsoft Excel-Dateien (*.xls), *.xls", _
Title:="Select files", _
MultiSelect:=True)
If IsArray(varRetVal) Then
On Error Resume Next
For n = LBound(varRetVal) To UBound(varRetVal)
Workbooks.Open varRetVal(n)
Next
On Error GoTo 0
End If
''Could be used for the selected path ?
''Attach the file
objNotesField = objNotesField.EmbedObject( 1454, "", ActiveWorkbook.FullName)
''Send the e-mail
objNotesDocument.Send (0)
'' Message
msg = "E-Mail sent“
MsgBox msg, vbInformation, "Send Notesmail"
''Release storage
Set objNotesSession = Nothing
Set bjNotesSession = Nothing
Set objNotesMailFile = Nothing
Set objNotesDocument = Nothing
Set objNotesField = Nothing
''Set return code
SendMail = True
Exit Function
''Error message
SendMailError:
msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox msg, , "Error", Err.HelpFile, Err.HelpContext
SendMail = False
End Function
Thanks a lot for your help!
Dim objNotesSession As Object
Dim objNotesMailFile As Object
Dim objNotesDocument As Object
Dim objNotesField As Object
Dim varRetVal As Variant
Dim n As Integer
Function SendMail()
On Error GoTo SendMailError
EMailSendTo = "test@test.com"
EMailCCTo = ""
EMailBCCTo = ""
EMailSubject = "test“
''Establish Connection to Notes
Set objNotesSession = CreateObject("Notes.NotesS
''Establish Connection to Mail File
Set objNotesMailFile = objNotesSession.GETDATABAS
''Open Mail
objNotesMailFile.OPENMAIL
''Create New Memo
Set objNotesDocument = objNotesMailFile.CREATEDOC
''Create 'Subject Field'
Set objNotesField = objNotesDocument.APPENDITE
''Create 'Send To' Field
Set objNotesField = objNotesDocument.APPENDITE
''Create 'Copy To' Field
Set objNotesField = objNotesDocument.APPENDITE
''Create 'Blind Copy To' Field
Set objNotesField = objNotesDocument.APPENDITE
''Create 'Body' of memo
Set objNotesField = objNotesDocument.CREATERIC
With objNotesField
.APPENDTEXT "Text"
.ADDNEWLINE 1
.APPENDTEXT "Text2"
.ADDNEWLINE 2
End With
‘‘CRITICAL PART
''Open dialog for file selection
varRetVal = Application.GetOpenFileNam
FileFilter:="Microsoft Excel-Dateien (*.xls), *.xls", _
Title:="Select files", _
MultiSelect:=True)
If IsArray(varRetVal) Then
On Error Resume Next
For n = LBound(varRetVal) To UBound(varRetVal)
Workbooks.Open varRetVal(n)
Next
On Error GoTo 0
End If
''Could be used for the selected path ?
''Attach the file
objNotesField = objNotesField.EmbedObject(
''Send the e-mail
objNotesDocument.Send (0)
'' Message
msg = "E-Mail sent“
MsgBox msg, vbInformation, "Send Notesmail"
''Release storage
Set objNotesSession = Nothing
Set bjNotesSession = Nothing
Set objNotesMailFile = Nothing
Set objNotesDocument = Nothing
Set objNotesField = Nothing
''Set return code
SendMail = True
Exit Function
''Error message
SendMailError:
msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox msg, , "Error", Err.HelpFile, Err.HelpContext
SendMail = False
End Function
1) I would retry to open the links I gave since there is good info there.
copy and paste into your brower if needed.
2) In any case, I would put the filenames into your default open worksheet somewhere, and then use the code I provded to attach them since trying to open and attach them could be problematic.
I hope this helps !
copy and paste into your brower if needed.
2) In any case, I would put the filenames into your default open worksheet somewhere, and then use the code I provded to attach them since trying to open and attach them could be problematic.
I hope this helps !
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
BTW, sysExpert.. the links really don't work. Maybe those have been deleted?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please post the code you have so far.
I hope this helps !