?
Solved

VBA Outlook 2000 attachment

Posted on 2004-09-10
4
Medium Priority
?
295 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 500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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…
Simple Linear Regression
Suggested Courses

777 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