Solved

VBA Outlook 2000 attachment

Posted on 2004-09-10
4
287 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
A short article about a problem I had getting the GPS LocationListener working.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now