VBA: msgbox doesn't work

yky

Well-known Member
Joined
Jun 7, 2011
Messages
1,881
Office Version
  1. 2010
Platform
  1. Windows
VBA Code:
msgbox "This Worksheet is not password protected"

Does anyone know what's wrong with the above code?

If the code is working, Excel automatically changes msgbox to MsgBox. Now, Excel doesn't do that and I got an error message saying "Object variable or With block variable not set.."

Is msgbox now a variable?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Best guess is you created a variable called msgbox.
 
Upvote 0
Thanks for the reply.

Can reserved words be used as variable names? I thought that couldn't be done.

I suspected the file was corrupted. So, I copied the module to a newly created file, saved it, and then opened it. "msgbox" became "MsgBox". Even without running the code, I knew the problem had been solved.
 
Upvote 0
Solution
There are some words that cannot be used for the names of variables, but most can be used.
But you can use MsgBox as a variable or the name of a procedure, although it may cause problems.
 
  • Like
Reactions: yky
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,930
Members
449,195
Latest member
Stevenciu

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