Object variable or With block not defined

Cunning

Board Regular
Joined
Jul 8, 2008
Messages
62
I keep getting runtime error 91 Object Variable or With block not defined for the following VBA.

Private Sub CommandButton1_Click()

ActiveSheet.Unprotect Password:=TextBox1.Text

Unload Me

End Sub

How can I rectify this?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Is a particular line highlighted when you get that error? If not choose Tools|Options|General tab, check Break in Class Module and click OK. Is a line highlighted when you get the error now?
 
Upvote 0
It reports

ActiveSheet.Unprotect Password:=TextBox1.Text

This as the error. I'm guessing it's the TextBox1.Text variable that's not defined.
 
Upvote 0
I can't reproduce your error. If TextBox1 doesn't exist I get an 'Object required' error not an 'Object Variable not set error'. With Option Explict at the top of the module I get a compile error if TextBox1 doesn't exist. Do you?
 
Upvote 0
Unfortunately I'm struggling to replicate the error on my machine. It's being used on a number of computers across 3 companies and one companies produces the error.

I have Option Explicit set on mine and produce no errors at all.
 
Upvote 0
Apologies,
This is in the userform and runs on OK.

The idea is that people enter the sheet specific password via a click of the button here rather than having to go through the menus to unprotect.
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,876
Members
452,949
Latest member
Dupuhini

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