VBA: Problem when addressing Workbook or Window via String

bobbel85

New Member
Joined
Aug 16, 2018
Messages
1
Hello,

Does anyone know the bug or problem where you get an error message (error 9 or 91) when you address a "window" or a "workbook" with a string like this?

Code:
strFile = "NameOfWorkbook"

Windows(strFile).visible = false
Workbooks(strFile).Close

The strange thing is, that this code is running on a lot machines in our Company without any error, but on a few it shows this behavior.
Furthermore, if I'm (with my user-account) running the code on their PC everything is fine; or if they run the code on another pc it is also fine.
So I guess it must be a special combination of their Excel/windows-Setting.

Perhaps somebody has heard of a bug like this and can me give a hint, where I can search for it.

thx in advance



a desperate VBA-amateur
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Welcome to the forum.

You should use Workbooks(strFile) and make sure you include the file extenstion in the strFile variable. That will always work, regardless of desktop settings.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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