Macro worked yesterday, today it falls over!

chuckles1066

Banned
Joined
Dec 20, 2004
Messages
372
I have a macro that checks that another file is open before doing anything else - if the file isn't open a message box pops up informing the user and then exits the sub.

Worked fine yesterday.

Today I've run it and it falls over at this point - I think it was error 404 or similar, "object required".

I have acquired a little knowledge of VBA and so moved the Dim wb as Workbooks reference out of the global bit at the start of the macro and down to the relevant bit of code.

Now it works fine.

But, just so I'm armed for future reference, why would something work yesterday and not today?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
At a guess, your code took a different path through your coding structure ... maybe an IF test was true today that wasn't true yesterday, and a variant result was applied to the wb object ... maybe. Hard to say without even seeing the code.
 
Upvote 0
Yesyerday you may have run the code one or more times resulting in a (global) variable being created and/or assigned a value, then subsequent runs relied upon the variable existing and/or having a value.

Today you may have run the code and that variable either didn't exist or didn't have a value or had the wrong value, resulting in the error.

So basically what Glenn suggested.

PS. Instead of popping up a message box, could you not simply open the file in your program?
 
Upvote 0
You can import a text file in code ... just use the macro recorder to record yourself opening the file the way you want. Then incorporate that into your original code.
 
Upvote 0
Well flap me sideways, never knew you could but I've just tried it at home and it does generate code.

Thanks for that, I'll give it a whirl on Monday.
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,345
Members
452,907
Latest member
Roland Deschain

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