LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Worksheet.Unprotect within WorkbookBeforeSave event fails if S

Just came across this issue in Excel 2007 as well.

The problem we were having was that you couldn't add a worksheet or delete a
worksheet.

Using this solution seemed to work.

"bta" wrote:

If TargetWorkbook Is ActiveWorkbook, a work-around is to execute the builtin
command bar control "File Save" instead of TargetWorkbook.Save
Here a code example:

'http://support.microsoft.com/kb/213552
Const id_menu_item_SAVE As Long = 3
Const id_menu_item_SAVE_AS As Long = 748
Const id_menu_main_FILE As Long = 30002
Const title_worksheet_menu_bar As String = "Worksheet Menu Bar"


Dim builtin_save As CommandBarControl
Dim builtin_save_as As CommandBarControl



Private Sub FindSomeBuiltinCommands()

Dim menu_item As CommandBarControl
Dim popup_menu As CommandBarPopup



Set popup_menu =
Application.CommandBars(title_worksheet_menu_bar). FindControl(Type:=msoControlPopup, ID:=id_menu_main_FILE)

For Each menu_item In popup_menu.Controls
If menu_item.ID = id_menu_item_SAVE Then Set builtin_save = menu_item
If menu_item.ID = id_menu_item_SAVE_AS Then Set builtin_save_as =
menu_item
Next

End Sub



Private Sub DoSave()

Call builtin_save.Execute
' When using "Call ThisWorkbook.Save" instead,
"Worksheet.Unprotect/.Protect" does NOT work !!!
End Sub



Private Sub TEST()

Call FindSomeBuiltinCommands
Call DoSave
End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Worksheet.Unprotect within WorkbookBeforeSave event fails if Save initiated by VB Dean Meyer Excel Programming 3 June 8th 07 12:30 AM
Macro to Unprotect save worksheet and protect it again. holy41 Excel Programming 2 July 31st 06 09:47 PM
event after worksheet unprotect sam[_8_] Excel Programming 2 June 29th 06 08:28 AM
Worksheet Save Event ExcelMonkey[_17_] Excel Programming 3 January 24th 04 03:04 PM
Save As - Multiple Sheets fails to save as text file Ravee Srinivasan Excel Programming 2 November 10th 03 04:05 PM


All times are GMT +1. The time now is 06:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"