-
Solved: Code inconsistancey
I use this code on my laptop and it works fine. Using it on my works computer I get an error on the sheet unprotect line. Is there a different way to write it so it will work on all computers?
I've used:
Sheets("Labor worksheet").UnProtect password:="password"
Sheets("Labor worksheet").UnProtect "password"
and then this:
[VBA]
Dim psword, pword
pword = "password"
psword = InputBox("Enter password to make changes")
If psword <> pword Then
MsgBox "Sorry, incorrect password"
Exit Sub
End If
If psword = pword Then
ThisWorkbook.Unprotect password:="thisbook"
Sheet10.Unprotect password:="viper" 'error line
UnHideColumn
End If
[/VBA]
Thanks
-
Does every workbook have Sheet10? That doesn't seem to be the normal way to refer to sheets.
Software: LibreOffice 3.3 on Mac OS X 10.6.5
(retired Excel 2003 user, 3.28.2008 )
Humanware: Older than dirt
--------------------
old, slow, and confused
but at least I'm inconsistent!
Rich
-
No not every workbook has a sheet10. But the activeworkbook does. Like I said, I get this error only on one computer. I've even changed the code to ActiveSheet.Unprotect password:="" and get a runtime error 1004. Makes no sense to me.
The reverse has no errors and I use Sheet10.Protect password:=""
Is there a way that I can check if the sheet is protected then if it is unprotect it? I've tried:
If Activesheet.Protection = False Then Activesheet.Unprotect password:="" but again got a doesn't support this error.
-
-
Thanks,
No the password is the same, if I use the Tools|Unprotect Worksheet it will unprotect with the password stored in the code. It's just really wierd that it does this.
-
Sounds like a VBA file corruption on one of the hard-drives. Try defragging and/or "detect and repair"
You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you
The major part of getting the right answer lies in asking the right question...
Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.
-
Is there a way to bring up the password dialog box? Unfortunately I cannot do the detect and repair since this is on a corporate computer. As long as I enter the password using Tools|Unprotect it works fine just not with code.
-
For the worksheet?[vba]Application.Dialogs(xlDialogProtectDocument).Show[/vba]
You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you
The major part of getting the right answer lies in asking the right question...
Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.
-
Thanks for all your help. I had to go a different route. I really don't quite understand what is going on but I didn't supply a password in the code and just protected it without a password. Worked fine when the code unprotected the sheet without a password. When the code protected the worksheet, the code couldn't unprotect it.
So I just hid all forumula's and set the scrollarea upon the workbook opening for that worksheet so at least the outside formulas are safe. The rest should be okay.
Again thanks for all the help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules