Home |
Search |
Today's Posts |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Brian,
Glad to be of any help... You fell into an Excel Trap - when you delete rows, columns, sheets etc - deleting # 1 makes # 2 a new # 1 (if you understand that - you have it made). So you work from the highest number to the lowest number. Delete # 2 and than delete # 1. To make it even easier - use a loop Dim sh as Integer For sh = 2 to 1 step -1 With Sheets(sh) .visible .select ' not sure if you need this, but I sometimes get an error if I don't use it. .unprotect .delete End With Next It's nice to believe this Thanks for your help. You're right that an experienced user could overcome whatever I do, but then I would hope that if they're that knowledgeable they will appreciate the fact that it is designed to avoid them using old information. We'll see. but there are a lot of people out their "Without Respect". And it really isn't necessary to delete the sheets (unless that is what you want). You can do the check, flash a message to the user, set a pause, and than auto-close the workbook. ThisWorkbook.Close False All you can really do is protect the Good User from making unintentional errors. That's all that Excel protection really accomplishes. And adding a password to the VBA protects the code (this one is harder to break). Go to the VB Editor and go to properties - there is a tab to set a password (note that it doesn't take effect until the workbook is saved and closed). happy Exceling... -- steveB Remove "AYN" from email to respond "Brian C" wrote in message ... Hi Steve, Thanks for your help. You're right that an experienced user could overcome whatever I do, but then I would hope that if they're that knowledgeable they will appreciate the fact that it is designed to avoid them using old information. We'll see. Here's what I'm trying to get to work. I want to unprotect 2 sheets, and then delete them if they were loaded from the C or D drive. I think I have the drive ID part down and the Unprotect down, but I can't get the delete to work. The code I'm using for that part is: sDrive = Left(ThisWorkbook.Path, 1) If UCase(sDrive) = "C" Or UCase(sDrive) = "D" Then Application.DisplayAlerts = False Sheets(5).Visible = True Sheets(1).Unprotect Sheets(2).Unprotect Sheets(1).Delete Sheets(2).Delete MsgBox ("This Application Must be Launched from the RETAIL TOOLBOX") End If Application.DisplayAlerts = True |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Links to mapped drive change to refer to local hard drive | Links and Linking in Excel | |||
Can I save to hard drive AND my flash drive at the same time? | Excel Discussion (Misc queries) | |||
Userform Local Drive & Network drive question | Excel Programming | |||
Identify CD-Rom drive | Excel Programming | |||
Pasting a range of information from a foler on F Drive to another folder on same drive | Excel Programming |