Runtime Error 9

PKennedyG77

New Member
Joined
Jan 2, 2016
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hi guys. This is a strange one.

A colleague of mine keeps getting a runtime error 9 whenever he tries to run a vba code.

The code opens up a second workbook and looks to activate the relevant workbook when appropriate.

The code is

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif] Sub NormalWeek62()
TheFirst = 0
FirstRow = 0
LastRow = 0[/FONT]

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Workbooks("Atlas62 " & TheYear & "").Activate
Sheets("" & WeekIdentifier & "" & TheWeek & "").Activate
Range("CH2").Select 'Goes to top of data ranges
Yesterday = WeekdayName(TodayNumber - 1, False, vbSunday) 'takes 1 from current day to get yesterday[/FONT]


It crashes with the runtime error 9 on the 4th Line (highlighted red). TheYear and WeekIdentifier variables are taken from another Public macro. It is showing the correct value when I hover the cursor over it.
Strange thing is, it works perfectly fine on my laptop.

It just does not want to activate the other workbook.

I'm confused. Could it be one of the Excel settings?

Thanks
Pat Kennedy
 
Last edited:

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
missing what. Rank amateur here.

If you mean that the workbook is not there, it is and the year is also there.
 
Upvote 0
Try adding the file extension to the workbook name.
 
Upvote 0
Thanks, will give that a go but why does it work ok on my laptop and not his?
Will be two weeks before he is back and I can try this
 
Upvote 0
It's down to the system settings.
I suspect that you have "Hide known file extensions" checked, whilst your colleague doesn't.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

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