Solved

script to attach pdf to outlook message does no work

Posted on 2004-08-10
9
278 Views
Last Modified: 2010-05-02
I'm running the following code to attach a pdf report to an Outlook mail message. The reference object library has been set to Microsoft Outlook 9.0 object library. Nothing happens, no errors, no nothing. What am I missing?....Thanks Ziggy

Function attpdf()
Dim strRecipient As String
    Dim strSubject As String
    Dim strAttachments As String
    Dim objMailItem As Outlook.MailItem
    Dim objOutlookAttach As Outlook.Attachment      
    Dim olkApp As Outlook.Application
    Dim olkNameSpace As NameSpace
       
    Set olkApp = New Outlook.Application
   
    Set olkNameSpace = olkApp.GetNamespace("MAPI")
    Set objMailItem = olkApp.CreateItem(olMailItem)

With objMailItem
      '  .To = Forms!frmOrders!contEmail
        .To = "esql"
        .Recipients.ResolveAll
        .Subject = "eProject Expenses Claim Report"
             
          Set objOutlookAttach = .Attachments.Add("c:\pdfreports\output.pdf")    

   Debug.Print "111"                                                                                             End With
End Function
 
0
Comment
Question by:zzbielski
  • 4
  • 3
  • 2
9 Comments
 
LVL 22

Accepted Solution

by:
DarkoLord earned 500 total points
ID: 11766604
Just add .Send line and it should work

Darko
0
 
LVL 76

Expert Comment

by:David Lee
ID: 11766663
Your code looks fine to me.  I pasted it into a project, created a folder on my c: drive called pdfreports, created a file called output.pdf, and then ran your code.  It attached the file without a problem.  I'm using the Microsoft Outlook Object 11.0 Library though.  I don't think that should make a difference though.  Have you tried stepping the code through the debugger to see what's happening?  Is the message object being created okay?
0
 

Author Comment

by:zzbielski
ID: 11766745
Thank you for your help, I added the .send line and it worked just fine. Maybe the Outlook Object 11.0 sends automatically?

Ziggy
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 76

Expert Comment

by:David Lee
ID: 11766752
Are we talking about the message not sending or the file not attaching?  I was thinking the latter since the original post only mentioned attaching.
0
 
LVL 22

Expert Comment

by:DarkoLord
ID: 11766774
Well the automated outlook instance should start invisible so there should really nothing (visible) happen when you attach the file to a message...

Darko
0
 
LVL 76

Expert Comment

by:David Lee
ID: 11766795
No, you still have to issue a send command in Outlook Object 11. All you mentioned in your original post was attaching so I took the problem to be that the attachment was getting attached, not that the message was sending.    
0
 
LVL 76

Expert Comment

by:David Lee
ID: 11766812
Ooops, that last bit should read "not that the message wasn't sending".
0
 

Author Comment

by:zzbielski
ID: 11766849
sorry for the confusion, I was testing the attach feature and forgot to include the .send command. That's why it was so frustrating.
0
 
LVL 22

Expert Comment

by:DarkoLord
ID: 11766867
Well thats why we are here :)))

Darko
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

831 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