[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

script to attach pdf to outlook message does no work

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
zzbielski
Asked:
zzbielski
  • 4
  • 3
  • 2
1 Solution
 
DarkoLordCommented:
Just add .Send line and it should work

Darko
0
 
David LeeCommented:
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
 
zzbielskiAuthor Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
David LeeCommented:
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
 
DarkoLordCommented:
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
 
David LeeCommented:
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
 
David LeeCommented:
Ooops, that last bit should read "not that the message wasn't sending".
0
 
zzbielskiAuthor Commented:
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
 
DarkoLordCommented:
Well thats why we are here :)))

Darko
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now