Solved

VBA Outlook 2000 attachment

Posted on 2004-09-10
4
291 Views
Last Modified: 2010-04-17
I am writing some code that exports a table to a .csv file and need to be able to email the .csv file. I have the code to email from VBA but i havnt a clue how to add an attachment. Does anyone know how to do this?

Here is the code i have so far and the code which i thought it was to add the attachments

Dim OLAPP As Object
    Dim OLMMM As Object
    Set OLAPP = CreateObject("outlook.Application")
    Set OLMMM = OLAPP.createitem(0)

   
    With OLMMM
    .subject = "Stompin Export"
    .To = "blah@blah.net"
    .Body = "Netsound's Stompin Records Export (.CSV)"
    .attachments.Add (Forms!export.export)
    End With

If MsgBox("Do you wish to preview the email before sending?", vbQuestion + vbYesNo, "Preview?") = vbYes Then
    OLMMM.display
   
    Else
   
    With OLMMM
    .send
    End With
                       
          End If
0
Comment
Question by:cg_medistox
[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
  • 2
  • 2
4 Comments
 
LVL 50

Accepted Solution

by:
Dave Brett earned 125 total points
ID: 12032220
Hi,

I'd think you should debug the string returned by Forms!export.export.

My slight mod of your code worked fine below when I attached a file with the pathname C:\test\temp.csv

Cheers

Dave

Sub Mail()
    Dim OLAPP As Object, OLMMM As Object
    Set OLAPP = CreateObject("outlook.Application")
    Set OLMMM = OLAPP.createitem(olMailItem)

    With OLMMM
        .Subject = "Stompin Export"
        .To = "blah@blah.net"
        .Body = "Netsound's Stompin Records Export (.CSV)"
        .Attachments.Add ("C:\test\temp.csv")
    End With

    If MsgBox("Do you wish to preview the email before sending?", vbQuestion + vbYesNo, "Preview?") = vbYes Then
        OLMMM.display
    Else
        OLMMM.send
    End If
End Sub
0
 
LVL 4

Author Comment

by:cg_medistox
ID: 12033570
I declared a string and passed the field into the string instead. I dont understand why it didn't work before??

Here is the code i used in case anyone wants to do this in future

Code:

    Dim StrPath As String
    Dim OLAPP As Object, OLMMM As Object
    Set OLAPP = CreateObject("outlook.Application")
    Set OLMMM = OLAPP.createitem(0)
    StrPath = Forms!export.export

    With OLMMM
        .Subject = "Stompin Export"
        .To = "blah@blah.net"
        .Body = "Netsound's Stompin Records Export (.CSV)"
        .Attachments.Add (StrPath)
    End With

    If MsgBox("Do you wish to preview the email before sending?", vbQuestion + vbYesNo, "Preview?") = vbYes Then
        OLMMM.display
    Else
        OLMMM.send
    End If
0
 
LVL 4

Author Comment

by:cg_medistox
ID: 12033578
Forgot to say, thanks
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 12033584
Thanks for the grade
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

738 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