ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Prevent saving and allow only through Macro (https://www.excelbanter.com/excel-discussion-misc-queries/134740-prevent-saving-allow-only-through-macro.html)

Lester from AUS

Prevent saving and allow only through Macro
 
I am contracting an excel template and need to stop users saving the file
using €śSave€ť or €śSave As€ť. I am able to do this by using the private sub
below:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Me.Saved = True
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
End Sub

I also understand that by switching to €śDesigner€ť mode you can save the file
and once re opened designer mode will be switched off. What I need is to
allow saving using a macro, is there a code that I can insert in the macro to
switch designer mode?

Many thanks for your help


JLatham

Prevent saving and allow only through Macro
 
Have you considered using a Public boolean flag that your Save macro would
set to true and that the two workbook events would examine and if the flag is
false, assume File | Save/Save As was used and perform as you have them
programmed. But if the flag is True, simply set it to False and permit the
operations (or at least the Save).

??

"Lester from AUS" wrote:

I am contracting an excel template and need to stop users saving the file
using €śSave€ť or €śSave As€ť. I am able to do this by using the private sub
below:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Me.Saved = True
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
End Sub

I also understand that by switching to €śDesigner€ť mode you can save the file
and once re opened designer mode will be switched off. What I need is to
allow saving using a macro, is there a code that I can insert in the macro to
switch designer mode?

Many thanks for your help


Dave Peterson

Prevent saving and allow only through Macro
 
If you're in design mode, then those events won't fire.

I don't see how you can anything you put into any of your event code can turn
this back to normal.



Lester from AUS wrote:

I am contracting an excel template and need to stop users saving the file
using €śSave€ť or €śSave As€ť. I am able to do this by using the private sub
below:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Me.Saved = True
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
End Sub

I also understand that by switching to €śDesigner€ť mode you can save the file
and once re opened designer mode will be switched off. What I need is to
allow saving using a macro, is there a code that I can insert in the macro to
switch designer mode?

Many thanks for your help


--

Dave Peterson


All times are GMT +1. The time now is 07:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com