PDA

View Full Version : [SOLVED] Modify Code to Unprotect Workbook Prior to Deleting Worksheet



sbubendorf
09-28-2005, 02:09 PM
Sub DeleteActiveWS()
'Every macro should have this of course...
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
'Every macro should have this of course...
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

Can someone help me to modify the code above to unprotect the active workbook (no password) prior to deleting the active sheet? The code, as posted, "chokes" on protected workbooks, but will work fine if I manually turn off the workbook protection.

Note: code above was found at the following address:
http://www.mvps.org/dmcritchie/excel/sheets.htm

THANK YOU VERY MUCH FOR ANY HELP THAT CAN BE PROVIDED !!!

(Excel 2003, Windows XP Pro)
(Using the code above as an add-in.)
(Absolute Beginner @ Excel Macros.)

Jacob Hilderbrand
09-28-2005, 02:44 PM
If there is no password...

ActiveWorkbook.Unprotect

Otherwise


ActiveWorkbook.Unprotect Password:="MyPassword"

sbubendorf
09-29-2005, 06:03 AM
THANK YOU, DRJ !!! That was exactly what I needed !!!http://vbaexpress.com/forum/images/smilies/023.gif