Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Public Variable problem

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 464
Default Public Variable problem

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Public Variable problem

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Public Variable problem

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Public Variable problem

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Public Variable problem

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Public Variable problem

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Public Variable problem

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Public Variable problem

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
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
Public variable (or Public Const?) Brettjg Excel Programming 14 April 23rd 09 11:30 PM
Public variable (or Public Const?) Tim Williams[_2_] Excel Programming 0 April 23rd 09 06:33 AM
Problem with Public Variable value being changed. [email protected] Excel Programming 2 January 2nd 08 08:31 PM
strange problem with public variable Gary Keramidas Excel Programming 2 July 8th 07 03:58 PM
Public variable problem moonhk Excel Programming 13 December 8th 06 08:38 AM


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