Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sending emails with attachment …

Posted on 2006-11-06
12
Medium Priority
?
627 Views
Last Modified: 2013-12-18
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.
0
Comment
Question by:Andrew420
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 63

Expert Comment

by:SysExpert
ID: 17881449
I would suggest that you Use excel VBA to choose the files and put the file names/paths in a worksheet, so that they can be accessed, and then  attach from the list of files into Notes via VBA.

Please post the code you have so far.

I hope this helps !
0
 
LVL 63

Expert Comment

by:SysExpert
ID: 17881643
0
 
LVL 63

Expert Comment

by:SysExpert
ID: 17881683
also
http://www.experts-exchange.com/Applications/Email/Lotus_Notes_Domino/Q_21677209.htm


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_ATTACHMENT, "",Attach1 )
Call rtItem.EmbedObject(EMBED_ATTACHMENT, "",Attach2 )
Call doc.send (False)

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17887893
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.
0
 
LVL 63

Expert Comment

by:SysExpert
ID: 17889855
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

0
 

Author Comment

by:Andrew420
ID: 17891542
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.GetOpenFileName' 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.NotesSession")

''Establish Connection to Mail File
Set objNotesMailFile = objNotesSession.GETDATABASE("", "")

''Open Mail
objNotesMailFile.OPENMAIL

''Create New Memo
Set objNotesDocument = objNotesMailFile.CREATEDOCUMENT

''Create 'Subject Field'
Set objNotesField = objNotesDocument.APPENDITEMVALUE("Subject", EMailSubject)

''Create 'Send To' Field
Set objNotesField = objNotesDocument.APPENDITEMVALUE("SendTo", EMailSendTo)

''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 "Text"
    .ADDNEWLINE 1
    .APPENDTEXT "Text2"
    .ADDNEWLINE 2
End With

‘‘CRITICAL PART
''Open dialog for file selection
  varRetVal = Application.GetOpenFileName( _
        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


0
 
LVL 63

Expert Comment

by:SysExpert
ID: 17891730
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 !
0
 
LVL 18

Accepted Solution

by:
marilyng earned 1000 total points
ID: 17922123
I can be wrong here, but you probably need to open the application File Picker dialog box at your critical note.

This excel button does that.  It allows the user to select files and return the full path of the selected document(s).  It copies these to tmpFiles string, and then splits the string into a variant: vSelFiles that you can step through to attach to the notes document in your code.

Once you have the file names, then loop through the variant to attach the file to the Notes e-mail.

---------------------------------------------------------------------

Private Sub CommandButton1_Click()
   'Declare a variable as a FileDialog object.
    Dim fd As FileDialog
    Dim vSelFiles As Variant
    Dim tmpFiles As String

    'Create a FileDialog object as a File Picker dialog box.
    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    'Declare a variable to contain the path
    'of each selected item. Even though the path is a String,
    'the variable must be a Variant because For Each...Next
    'routines only work with Variants and Objects.
    Dim vrtSelectedItem As Variant

    'Use a With...End With block to reference the FileDialog object.
    With fd

        'Use the Show method to display the File Picker dialog box and return the user's action.
        'The user pressed the action button.
        If .Show = -1 Then

            'Step through each string in the FileDialogSelectedItems collection.
            For Each vrtSelectedItem In .SelectedItems
                tmpFiles = tmpFiles + vrtSelectedItem + ","

                'vrtSelectedItem is a String that contains the path of each selected item.
                'You can use any file I/O functions that you want to work with this path.
                'This example simply displays the path in a message box.
                MsgBox "The path is: " & vrtSelectedItem
            Next vrtSelectedItem
        'The user pressed Cancel.
        Else
        End If
    End With

      vSelFiles = Split(tmpFiles, ",")
   
    'This part you can add to your Lotus Notes Body loop....
    'And attach files that have been selected.
    If Len(tmpFiles) > 0 Then
      For Each sFile In vSelFiles
        If Len(sFile) > 0 Then
            MsgBox "Here is collected file: " + sFile
        End If
      Next sFile
    End If
   
    'Set the object variable to Nothing << Important!!.
    Set fd = Nothing
         
End Sub
0
 
LVL 18

Expert Comment

by:marilyng
ID: 17922126
BTW, sysExpert.. the links really don't work.  Maybe those have been deleted?
0
 
LVL 63

Assisted Solution

by:SysExpert
SysExpert earned 1000 total points
ID: 17938145
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question