Compile Error

  • Thread starter Patrick Simonds
  • Start date
P

Patrick Simonds

I can not figure out why I get a Compile Error (Expected Function or
Variable). It stops at : Module Protection.unprotect_all_sheets. If I
run the module on its own it works fine.


Private Sub CommandButton1_Click()

On Error GoTo Error

'ActiveWorkbook.ChangeFileAccess Mode:=xlReadWrite
Worksheets("January").Protect Password:="popcorn"


If TextBox1.Text = "popcorn" Then
Module Protection.unprotect_all_sheets
End If

If TextBox1.Text <> "popcorn" Then
Unload UserFormPassword
MsgBox "Invalid password - you cannot access this"

ThisWorkbook.Close False

Exit Sub

Else

Unload UserFormPassword

End If

Worksheets("January").Protect Password:=""

GoTo LastLine

Error:

ThisWorkbook.Close False

LastLine:

End Sub
 
D

Dave Peterson

If you're trying to run the unprotect_all_sheets procedure in the Protection
module:

Call Protection.unprotect_all_sheets
or
Protection.unprotect_all_sheets

If you don't have procedures with the same name, you could do:
Call unprotect_all_sheets
or
unprotect_all_sheets

(The module name isn't always necessary.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Prevent Printing 1
Lock down a workbook 0
Copy filtered data to sheet 2 1
SetFocus problem 3
Project / Libary error 1
Check cell value exactly 3
Prevent overwriting a file 8
vba if and goto statements 4

Top