Solved

VBA Outlook 2000 attachment

Posted on 2004-09-10
4
286 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
Comment Utility
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
Comment Utility
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
Comment Utility
Forgot to say, thanks
0
 
LVL 50

Expert Comment

by:Dave Brett
Comment Utility
Thanks for the grade
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
This is an explanation of a simple data model to help parse a JSON feed
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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