Outlook VBA

Johndinho

Board Regular
Joined
Mar 21, 2013
Messages
90
Hi,

Not sure if this is better suited here or the main forum, but here goes

I have the code below that is supposed to save an email attachment to a defined location on receipt in Outlook.

Code:
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
  Dim olApp As Outlook.Application
  Dim objNS As Outlook.NameSpace
  Dim objAtt As Outlook.Attachment
  Set olApp = Outlook.Application
  Set objNS = olApp.GetNamespace("MAPI")
  Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Items_ItemAdd(ByVal item As Object)


  Dim Msg As Outlook.MailItem
  Dim saveFolder As String
  If TypeName(item) = "MailItem" Then
    Set Msg = item
    ' ******************
    saveFolder = "C:\Automation"
    objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName        '<-------Error Here
    ' ******************
  Else
  End If
ProgramExit:
  Exit Sub
End Sub

When the email is received I get error "424-Object required" but it is defined above??

Anyone tell me where I am going wrong please?

Thanks,

John
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
you declared it, but i dont see where you assigned (created) it.


Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.createitem(olMailItem)

msgbox oMail.Attachments.count
 
Last edited:
Upvote 0
Thanks ranman,

I've tried adding your lines in several different places, restarting outlook each time and i still get the same error message..

I've changed what I'm looking for now - All I want is to open the attachment. Everything else I can do in Excel VBA. I'll start a new thread

Thanks
 
Upvote 0
Outlook VBA - Open Attachment

Hi,

I'm sure this is a lot easier than it appears to be..

I'm looking for some code to open a .xlsm attachment on receipt into Outlook. I have seen lots of examples, some using Shell, some using rules, some I swear are written in Martian but I cannot get a single one to work

HELP!!

Once the xlsm is open, I can load everything else I do into Excel VBA (where I am much more comfortable).

I don't understand why this has to be so hard!!!

Code:
On Receipt of email with attachment
Open the attachment
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top