Error 91 - Object variable not set - VBA Excel 2007

MikeL

Active Member
Joined
Mar 17, 2002
Messages
488
Office Version
  1. 365
Platform
  1. Windows
Hello,
I am having trouble naming an .XLS attachment from outlook. I appended the existing code because olAtt.FileName alone writes over existing files if I have multiple files with the same name:

-------------------------------
Select Case Right(olAtt.FileName, 4)
Case ".xls"
FileName = frmdownloadattchmts.TextBox1.Value & olAtt.FileName & Format(Item.ReceivedTime, "yyyy-mmm-dd")
olAtt.SaveAsFile FileName
i = i + 1

-----------------------------
Any help?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
olAtt.FileName contains the .xls extension?

In which case your FileName variable would contain the string "abc.xls2012-Jan-01", whereas it should read "abc2012-Jan-01.xls".

Just a guess, so could be wrong. :)
 
Upvote 0
If that error only began occurring when you added that new bit of code then the error message is telling you that your Item variable doesn't hold a reference to anything.
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,175
Members
449,071
Latest member
cdnMech

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