Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default ThisWorkbook.Save not working under Workbook_BeforeSave, Help!

Why doesn't the workbook get saved here ?

Private Sub Workbook_BeforeSave(ByVal SaveAsUi As Boolean, Cancel As
Boolean)
Application.EnableEvents = False
ThisWorkbook.Worksheets("Sales").Protect Password:="123",
UserInterfaceOnly:=True, Scenarios:=True, Contents:=True
ThisWorkbook.Save
ThisWorkbook.Worksheets("Sales").Unprotect Password:="123"
Cancel = True
Application.EnableEvents = True
End Sub

This sub get's called with ThisWorkbook.Save and debug does step
through it all the way, only it doesn't get saved?!

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default ThisWorkbook.Save not working under Workbook_BeforeSave, Help!

Hi Michel
code works for me. How do you recognize that this won't save your file?

--
Regards
Frank Kabel
Frankfurt, Germany


Michel wrote:
Why doesn't the workbook get saved here ?

Private Sub Workbook_BeforeSave(ByVal SaveAsUi As Boolean, Cancel As
Boolean)
Application.EnableEvents = False
ThisWorkbook.Worksheets("Sales").Protect Password:="123",
UserInterfaceOnly:=True, Scenarios:=True, Contents:=True
ThisWorkbook.Save
ThisWorkbook.Worksheets("Sales").Unprotect Password:="123"
Cancel = True
Application.EnableEvents = True
End Sub

This sub get's called with ThisWorkbook.Save and debug does step
through it all the way, only it doesn't get saved?!

Thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default ThisWorkbook.Save not working under Workbook_BeforeSave, Help!

Because you have set Cancel = True, which is telling the event to cancel the
save.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Michel" wrote in message
om...
Why doesn't the workbook get saved here ?

Private Sub Workbook_BeforeSave(ByVal SaveAsUi As Boolean, Cancel As
Boolean)
Application.EnableEvents = False
ThisWorkbook.Worksheets("Sales").Protect Password:="123",
UserInterfaceOnly:=True, Scenarios:=True, Contents:=True
ThisWorkbook.Save
ThisWorkbook.Worksheets("Sales").Unprotect Password:="123"
Cancel = True
Application.EnableEvents = True
End Sub

This sub get's called with ThisWorkbook.Save and debug does step
through it all the way, only it doesn't get saved?!

Thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default ThisWorkbook.Save not working under Workbook_BeforeSave, Help!

Hi Bob
but he saves the workbook manually (with disabling the events prior to
this so the BeforeSave event is not called again).

--
Regards
Frank Kabel
Frankfurt, Germany


Bob Phillips wrote:
Because you have set Cancel = True, which is telling the event to
cancel the save.


"Michel" wrote in message
om...
Why doesn't the workbook get saved here ?

Private Sub Workbook_BeforeSave(ByVal SaveAsUi As Boolean, Cancel As
Boolean)
Application.EnableEvents = False
ThisWorkbook.Worksheets("Sales").Protect Password:="123",
UserInterfaceOnly:=True, Scenarios:=True, Contents:=True
ThisWorkbook.Save
ThisWorkbook.Worksheets("Sales").Unprotect Password:="123"
Cancel = True
Application.EnableEvents = True
End Sub

This sub get's called with ThisWorkbook.Save and debug does step
through it all the way, only it doesn't get saved?!

Thanks.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default ThisWorkbook.Save not working under Workbook_BeforeSave, Help!

I must admit to not trying it, just saw the Cancel = True.

Testing it, it also works for me now.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Frank Kabel" wrote in message
...
Hi Bob
but he saves the workbook manually (with disabling the events prior to
this so the BeforeSave event is not called again).

--
Regards
Frank Kabel
Frankfurt, Germany


Bob Phillips wrote:
Because you have set Cancel = True, which is telling the event to
cancel the save.


"Michel" wrote in message
om...
Why doesn't the workbook get saved here ?

Private Sub Workbook_BeforeSave(ByVal SaveAsUi As Boolean, Cancel As
Boolean)
Application.EnableEvents = False
ThisWorkbook.Worksheets("Sales").Protect Password:="123",
UserInterfaceOnly:=True, Scenarios:=True, Contents:=True
ThisWorkbook.Save
ThisWorkbook.Worksheets("Sales").Unprotect Password:="123"
Cancel = True
Application.EnableEvents = True
End Sub

This sub get's called with ThisWorkbook.Save and debug does step
through it all the way, only it doesn't get saved?!

Thanks.






Reply
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
Disable Save/Save As - not working? Silena K-K Excel Discussion (Misc queries) 3 December 11th 07 03:09 PM
HELP!!!! Calling a sub from Workbook_BeforeSave RocketMan[_2_] Excel Discussion (Misc queries) 4 May 31st 07 11:47 PM
Worksheet Buttons (Save, Save As, Cut, Paste, etc.) Not Working SuzieQ12345 Excel Worksheet Functions 5 January 21st 05 02:57 PM
Workbook_BeforeSave Bill Oertell Excel Programming 5 December 21st 03 07:33 PM
Workbook_BeforeSave() in xla Bent Kjeldsen Excel Programming 6 September 24th 03 01:49 PM


All times are GMT +1. The time now is 03:19 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"