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
Solved

VBA Outlook 2000 attachment

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
advertisement module in core php 4 170
recursion example 16 139
C# code editing and collaboration 3 131
tvirtualstringtree freeze when load too manny images 10 71
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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…

840 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