Forum

Runtime Error 91 "O...
 
Notifications
Clear all

Runtime Error 91 "Object Variable or with Block Variable not Set"

15 Posts
5 Users
0 Reactions
257 Views
(@stevenbehr1)
Posts: 92
Estimable Member
Topic starter
 

Hi,

 

I have made Database VBA with visible sheets. After converting to down from excel 2019 to 365 office it

comes up with Runtime error 91 "Object Varible or with Block Varible not Set".

 

Yet when I use it in 2019 nothing happens?????

 

Sub VisibleTrue()

DIM ws As worksheet

 

For Each ws In Activeworkbook.Sheets

ws.Visible = True

Next ws 

ActiveWindow.DisplayWorkbookTabs = True

Sheet9.Select

End Sub

 

I Also tried.

 

DIM As Worksheet

Set ws ActiveWorkbook

 

ECT.....

 

Have I missed something here or is it because of going from 2019 too 365

 

Thanks

 

Steve

 
Posted : 09/03/2020 7:06 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Steve,

Without your workbook I can't do anything.

Phil

 
Posted : 09/03/2020 10:11 pm
(@stevenbehr1)
Posts: 92
Estimable Member
Topic starter
 

Sorry Phil,

 

Here is the workbook.

 

Sorry once again

 

As stated in my reply email

 

Steve

 
Posted : 09/03/2020 10:35 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Steve,

I can't reproduce the error.  When I run VisibleTrue it runs without issue.

Do you get this error when you open the workbook?

What line of code is highlighted when the error occurs?

Have you tried debugging by stepping though the code line by line using F8?

regards

Phil

 
Posted : 10/03/2020 3:39 am
(@stevenbehr1)
Posts: 92
Estimable Member
Topic starter
 

Hi Phil,

 

Thats interesting. The error came up as soon as I transferred the database from my excel 2019 to 365 (work computer).

The error comes as soon as I hit enable editing or macro. The error indicates on VBA debug highlighted in yellow:

For Each ws In Activeworkbook.Sheets

I could bench test this tomorrow at another collueges computer and see if it debugs on that computer. All work computers run 365 - sad.

I had previously completed 3 databases and never had an issue with that visibletrue scenario coding.

Can you confirm if its a 365 or my 365 work computer or excel difference between 2019 and 365????

 

Thanks

 

Steve

 
Posted : 10/03/2020 4:29 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Steve,

I can't see why your code would run any differently on 2019 or 365.

Phil

 
Posted : 10/03/2020 9:47 pm
(@debaser)
Posts: 836
Member Moderator
 

Does it work properly if you enable macros, then save close and reopen the workbook? I suspect protected mode is interfering.

 
Posted : 11/03/2020 11:19 am
(@stevenbehr1)
Posts: 92
Estimable Member
Topic starter
 

Terrible sorry phil for not getting to you earlier...been swamped at work.

 

I've tried it on 2 work coleugue 365...and it works with no errors.

 

So im a bit perplexed on this maybe some of my 365 isn't working????

Anyway I leave at that and move on

 

Thanks for your help

 

Steve

 
Posted : 12/03/2020 3:04 am
(@purfleet)
Posts: 412
Reputable Member
 

Could you be running different versions of Excel i.e 32 bit or 64 bit? I know there are some differences between the 2 versions

Purfleet 

 
Posted : 12/03/2020 4:46 am
(@stevenbehr1)
Posts: 92
Estimable Member
Topic starter
 

Hi Purfleet,

 

I have looked on my Work 365 Excel and its running 32Bit.

 

My Personal excel 2019 64 bit.

 

So looks like a type of version that might have a some issues with

 

Steve

 
Posted : 13/03/2020 5:56 pm
(@debaser)
Posts: 836
Member Moderator
 

Nothing in your code is 32 vs 64 bit specific.

 

On the computers where it works, are you prompted to enable editing?

 
Posted : 14/03/2020 2:19 pm
(@stevenbehr1)
Posts: 92
Estimable Member
Topic starter
 

Yes of coarse Velouria>

The only way to work and function is to enable it and macro.

I have not asked or seen if my work colegues have 32bit 365 as yet.

Steve

 
Posted : 15/03/2020 3:11 am
(@debaser)
Posts: 836
Member Moderator
 

Steve,

My point is that if your workbook opens in protected mode and you then enable editing and macros, any code run in the Open event will not be able to access any application properties (such as Activeworkbook). If you save, close and then reopen it, so it should be trusted at that point, does the code then run without error (assuming you don't get any prompts)?

 
Posted : 17/03/2020 9:16 am
(@the-ms-dos-nerd)
Posts: 1
New Member
 

Excel will throw error 91 when calling Activeworkbook.Sheets while having multiple files with the same name open at the same time. This can cause random errors 91 in code that worked fine previously.

I don't know whether this was the problem in your case or not.

 
Posted : 18/07/2020 11:47 am
(@debaser)
Posts: 836
Member Moderator
 

But you can't have multiple files with the same name open in the same Excel instance.

 
Posted : 21/07/2020 7:16 am
Share: