Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have the line below in a module:
Public NoSave As Boolean In my Auto_Open routine I have: Sub Auto_Open() ' Events.Enable_Events If ActiveWorkbook.ReadOnly = True Then NoSave = True Protection.ProtectAllSheets Else NoSave = False Protection.UnProtectAllSheets End If Module7.StartPoint Module6.StartTimer End Sub Then I in ThisWorkbook ihave the following" Private Sub Workbook_BeforeClose(Cancel As Boolean) If NoSave = True Then ThisWorkbook.Close False End If If NoSave = False Then End If End Sub My problem is that when you click on either the Red X to close Excel or the smaller X to close the workbook you are still prompted to save the workbook. So it is not seeing NoSave as true, even when it was set to True in te Auto_Open routine. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
All depends on your code line;
If ActiveWorkbook.ReadOnly = True Then BTW, Public Variables MUST reside in a Public Module. -- Regards Dave Hawley www.ozgrid.com "ordnance1" wrote in message ... I have the line below in a module: Public NoSave As Boolean In my Auto_Open routine I have: Sub Auto_Open() ' Events.Enable_Events If ActiveWorkbook.ReadOnly = True Then NoSave = True Protection.ProtectAllSheets Else NoSave = False Protection.UnProtectAllSheets End If Module7.StartPoint Module6.StartTimer End Sub Then I in ThisWorkbook ihave the following" Private Sub Workbook_BeforeClose(Cancel As Boolean) If NoSave = True Then ThisWorkbook.Close False End If If NoSave = False Then End If End Sub My problem is that when you click on either the Red X to close Excel or the smaller X to close the workbook you are still prompted to save the workbook. So it is not seeing NoSave as true, even when it was set to True in te Auto_Open routine. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have other code that uses the If ActiveWorkbook.ReadOnly = True Then line
and it runs fine, but when I click on the Large X (very upper right corner) it does not see the active workbook as being ReadOnly. As far as I know NoSave As Boolean is in a public module. When I commented out the line I got a Variable not defined error. I also tried simplifying the code to: If ActiveWorkbook.ReadOnly = True Then ThisWorkbook.Close False" End If "ozgrid.com" wrote in message ... All depends on your code line; If ActiveWorkbook.ReadOnly = True Then BTW, Public Variables MUST reside in a Public Module. -- Regards Dave Hawley www.ozgrid.com "ordnance1" wrote in message ... I have the line below in a module: Public NoSave As Boolean In my Auto_Open routine I have: Sub Auto_Open() ' Events.Enable_Events If ActiveWorkbook.ReadOnly = True Then NoSave = True Protection.ProtectAllSheets Else NoSave = False Protection.UnProtectAllSheets End If Module7.StartPoint Module6.StartTimer End Sub Then I in ThisWorkbook ihave the following" Private Sub Workbook_BeforeClose(Cancel As Boolean) If NoSave = True Then ThisWorkbook.Close False End If If NoSave = False Then End If End Sub My problem is that when you click on either the Red X to close Excel or the smaller X to close the workbook you are still prompted to save the workbook. So it is not seeing NoSave as true, even when it was set to True in te Auto_Open routine. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try
Private Sub Workbook_BeforeClose(Cancel As Boolean) If NoSave = True Then Cancel = True Application.DisplayAlerts = False ThisWorkbook.Close False End If End Sub -- Jacob (MVP - Excel) "ordnance1" wrote: I have the line below in a module: Public NoSave As Boolean In my Auto_Open routine I have: Sub Auto_Open() ' Events.Enable_Events If ActiveWorkbook.ReadOnly = True Then NoSave = True Protection.ProtectAllSheets Else NoSave = False Protection.UnProtectAllSheets End If Module7.StartPoint Module6.StartTimer End Sub Then I in ThisWorkbook ihave the following" Private Sub Workbook_BeforeClose(Cancel As Boolean) If NoSave = True Then ThisWorkbook.Close False End If If NoSave = False Then End If End Sub My problem is that when you click on either the Red X to close Excel or the smaller X to close the workbook you are still prompted to save the workbook. So it is not seeing NoSave as true, even when it was set to True in te Auto_Open routine. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'd try:
Private Sub Workbook_BeforeClose(Cancel As Boolean) If NoSave = True Then me.saved = true ' a white lie to excel end if End Sub Since you lied to excel, it won't see any changes that need to be saved. So it won't prompt the user. And the close will just continue just like normal. ordnance1 wrote: I have the line below in a module: Public NoSave As Boolean In my Auto_Open routine I have: Sub Auto_Open() ' Events.Enable_Events If ActiveWorkbook.ReadOnly = True Then NoSave = True Protection.ProtectAllSheets Else NoSave = False Protection.UnProtectAllSheets End If Module7.StartPoint Module6.StartTimer End Sub Then I in ThisWorkbook ihave the following" Private Sub Workbook_BeforeClose(Cancel As Boolean) If NoSave = True Then ThisWorkbook.Close False End If If NoSave = False Then End If End Sub My problem is that when you click on either the Red X to close Excel or the smaller X to close the workbook you are still prompted to save the workbook. So it is not seeing NoSave as true, even when it was set to True in te Auto_Open routine. -- Dave Peterson |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sorry I did not get back sooner, got called away for work.
Things still are not working for me and I think I have tracked down my problem, just do not know how to fix it. The code below is a timer code to close my workbook after 15 minutes and it prevents my Workbook_BeforeClose from working. When I click on the small x or select close from the menu it works, but when I click on the large X it sees ActiveWorkbook.ReadOnly as false. Private Sub Workbook_BeforeClose(Cancel As Boolean) If ActiveWorkbook.ReadOnly = False Then ThisWorkbook.Close True End If If ActiveWorkbook.ReadOnly = True Then ThisWorkbook.Close False End If End Sub '''''''''''''''''''''''''''''''''''''''''''''''''' ' Code was found @ http://www.teachexcel.com/free-excel...ime-limit.html Option Explicit Sub StartTimer() Dim Start, Finish, TotalTime, TotalTimeInMinutes, TimeInMinutes Application.DisplayAlerts = True Cancel = False TimeInMinutes = 15 'Timer is set for 15 minutes; change as needed. If TimeInMinutes 5 Then TotalTimeInMinutes = (TimeInMinutes * 60) - (5 * 60) Start = Timer Do While Timer < Start + TotalTimeInMinutes DoEvents If Cancel = True Then GoTo Finished End If Loop Finish = Timer TotalTime = Finish - Start Application.DisplayAlerts = False End If Start = Timer Do While Timer < Start + (5 * 60) DoEvents If Cancel = True Then GoTo Finished End If Loop Finish = Timer TotalTime = Finish - Start Application.DisplayAlerts = False Finished: If ActiveWorkbook.ReadOnly = True Then ThisWorkbook.Close False Else ThisWorkbook.Close True End If End Sub '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''' |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Did you try all the suggestions?
ordnance1 wrote: Sorry I did not get back sooner, got called away for work. Things still are not working for me and I think I have tracked down my problem, just do not know how to fix it. The code below is a timer code to close my workbook after 15 minutes and it prevents my Workbook_BeforeClose from working. When I click on the small x or select close from the menu it works, but when I click on the large X it sees ActiveWorkbook.ReadOnly as false. Private Sub Workbook_BeforeClose(Cancel As Boolean) If ActiveWorkbook.ReadOnly = False Then ThisWorkbook.Close True End If If ActiveWorkbook.ReadOnly = True Then ThisWorkbook.Close False End If End Sub '''''''''''''''''''''''''''''''''''''''''''''''''' ' Code was found @ http://www.teachexcel.com/free-excel...ime-limit.html Option Explicit Sub StartTimer() Dim Start, Finish, TotalTime, TotalTimeInMinutes, TimeInMinutes Application.DisplayAlerts = True Cancel = False TimeInMinutes = 15 'Timer is set for 15 minutes; change as needed. If TimeInMinutes 5 Then TotalTimeInMinutes = (TimeInMinutes * 60) - (5 * 60) Start = Timer Do While Timer < Start + TotalTimeInMinutes DoEvents If Cancel = True Then GoTo Finished End If Loop Finish = Timer TotalTime = Finish - Start Application.DisplayAlerts = False End If Start = Timer Do While Timer < Start + (5 * 60) DoEvents If Cancel = True Then GoTo Finished End If Loop Finish = Timer TotalTime = Finish - Start Application.DisplayAlerts = False Finished: If ActiveWorkbook.ReadOnly = True Then ThisWorkbook.Close False Else ThisWorkbook.Close True End If End Sub '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''' -- Dave Peterson |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm sorry, I did try all suggestions offered. The only one that worked was
the one where I lied to Excel and said If ActiveWorkbook.ReadOnly = False then perform the function that I wanted done when the document opened as read only. The problem with that approach is that when the document is opened, not as read only, it would close without saving. I have other modules where I use the If ActiveWorkbook.ReadOnly = and the all work correctly. Every thing comes back to the timer routine. If I do not run it (it is started in the Auto_Open) everything works as expected. I even tried referring to the sub (shown below). That sub resided in the same module as the timer routine. ------------------------- Sub StopTimer() Cancel = True End Sub ------------------------ "Dave Peterson" wrote in message ... Did you try all the suggestions? ordnance1 wrote: Sorry I did not get back sooner, got called away for work. Things still are not working for me and I think I have tracked down my problem, just do not know how to fix it. The code below is a timer code to close my workbook after 15 minutes and it prevents my Workbook_BeforeClose from working. When I click on the small x or select close from the menu it works, but when I click on the large X it sees ActiveWorkbook.ReadOnly as false. Private Sub Workbook_BeforeClose(Cancel As Boolean) If ActiveWorkbook.ReadOnly = False Then ThisWorkbook.Close True End If If ActiveWorkbook.ReadOnly = True Then ThisWorkbook.Close False End If End Sub '''''''''''''''''''''''''''''''''''''''''''''''''' ' Code was found @ http://www.teachexcel.com/free-excel...ime-limit.html Option Explicit Sub StartTimer() Dim Start, Finish, TotalTime, TotalTimeInMinutes, TimeInMinutes Application.DisplayAlerts = True Cancel = False TimeInMinutes = 15 'Timer is set for 15 minutes; change as needed. If TimeInMinutes 5 Then TotalTimeInMinutes = (TimeInMinutes * 60) - (5 * 60) Start = Timer Do While Timer < Start + TotalTimeInMinutes DoEvents If Cancel = True Then GoTo Finished End If Loop Finish = Timer TotalTime = Finish - Start Application.DisplayAlerts = False End If Start = Timer Do While Timer < Start + (5 * 60) DoEvents If Cancel = True Then GoTo Finished End If Loop Finish = Timer TotalTime = Finish - Start Application.DisplayAlerts = False Finished: If ActiveWorkbook.ReadOnly = True Then ThisWorkbook.Close False Else ThisWorkbook.Close True End If End Sub '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''' -- Dave Peterson |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
What happened when you tested my suggestion?
ordnance1 wrote: I'm sorry, I did try all suggestions offered. The only one that worked was the one where I lied to Excel and said If ActiveWorkbook.ReadOnly = False then perform the function that I wanted done when the document opened as read only. The problem with that approach is that when the document is opened, not as read only, it would close without saving. I have other modules where I use the If ActiveWorkbook.ReadOnly = and the all work correctly. Every thing comes back to the timer routine. If I do not run it (it is started in the Auto_Open) everything works as expected. I even tried referring to the sub (shown below). That sub resided in the same module as the timer routine. ------------------------- Sub StopTimer() Cancel = True End Sub ------------------------ "Dave Peterson" wrote in message ... Did you try all the suggestions? ordnance1 wrote: Sorry I did not get back sooner, got called away for work. Things still are not working for me and I think I have tracked down my problem, just do not know how to fix it. The code below is a timer code to close my workbook after 15 minutes and it prevents my Workbook_BeforeClose from working. When I click on the small x or select close from the menu it works, but when I click on the large X it sees ActiveWorkbook.ReadOnly as false. Private Sub Workbook_BeforeClose(Cancel As Boolean) If ActiveWorkbook.ReadOnly = False Then ThisWorkbook.Close True End If If ActiveWorkbook.ReadOnly = True Then ThisWorkbook.Close False End If End Sub '''''''''''''''''''''''''''''''''''''''''''''''''' ' Code was found @ http://www.teachexcel.com/free-excel...ime-limit.html Option Explicit Sub StartTimer() Dim Start, Finish, TotalTime, TotalTimeInMinutes, TimeInMinutes Application.DisplayAlerts = True Cancel = False TimeInMinutes = 15 'Timer is set for 15 minutes; change as needed. If TimeInMinutes 5 Then TotalTimeInMinutes = (TimeInMinutes * 60) - (5 * 60) Start = Timer Do While Timer < Start + TotalTimeInMinutes DoEvents If Cancel = True Then GoTo Finished End If Loop Finish = Timer TotalTime = Finish - Start Application.DisplayAlerts = False End If Start = Timer Do While Timer < Start + (5 * 60) DoEvents If Cancel = True Then GoTo Finished End If Loop Finish = Timer TotalTime = Finish - Start Application.DisplayAlerts = False Finished: If ActiveWorkbook.ReadOnly = True Then ThisWorkbook.Close False Else ThisWorkbook.Close True End If End Sub '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''' -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Public variable (or Public Const?) | Excel Programming | |||
Public variable (or Public Const?) | Excel Programming | |||
Problem with Public Variable value being changed. | Excel Programming | |||
strange problem with public variable | Excel Programming | |||
Public variable problem | Excel Programming |