Error 91 - Object variable not set - VBA Excel 2007

MikeL

Active Member
Joined
Mar 17, 2002
Messages
440
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?
 

Some videos you may like

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Darren Bartrup

Well-known Member
Joined
Mar 13, 2006
Messages
1,295
Office Version
  1. 365
Platform
  1. Windows
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. :)
 

Colin Legg

MrExcel MVP, Like totally RAD man
Joined
Feb 28, 2008
Messages
3,497
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,484
Messages
5,596,407
Members
414,064
Latest member
Duncthegreat

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
Top