How do I bypass this timer if Im in Read Only???

jtbrown1955

New Member
Joined
Jan 12, 2005
Messages
40
I have this timer set up, but I want it disregarded if I'm in read only.

This is in ThisWorkbook

Private Sub Workbook_Open()
Reset
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Reset
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Reset
End Sub


This is in Module1

Sub Reset()
Static SchedSave
If SchedSave <> 0 Then
Application.OnTime SchedSave, "SaveWork", , False
End If
SchedSave = Now + TimeValue("00:59:00") ' 59 minutes
Application.OnTime SchedSave, "SaveWork", , True
End Sub
Sub SaveWork()
If Application.ThisWorkbook.ReadOnly = True Then
Application.ThisWorkbook.Saved = True
Else
ThisWorkbook.Save
End If
ThisWorkbook.Close
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

parry

MrExcel MVP
Joined
Aug 20, 2002
Messages
3,355
ThisWorkbook.ReadOnly will return true if the book is read only, and false if its not.
 

jtbrown1955

New Member
Joined
Jan 12, 2005
Messages
40

ADVERTISEMENT

Tazguy37 said:
Works in 2000 also.

What works? I didn't see an answer. The code I gave works fine, I just want the application to stay open if I'm in read only.
 

jtbrown1955

New Member
Joined
Jan 12, 2005
Messages
40

ADVERTISEMENT

Tazguy37 said:
parry said:
ThisWorkbook.ReadOnly will return true if the book is read only, and false if its not.

That works in 2000 also.

Ok, I got the original code off this forum. I put it in the workbook just like I was told here. Everything works fine. I want to change it so if I am in read only, the workbook will not close. I want to the application to stay running. The way it is now, the workbook will save AND close if it is edit mode when the timer runs out. I want to keep this. The workbook will not save, but will close if it is in read only. I don't want this. I want the application to stay open if it is in read only. I am new at this and I am trying to learn, but you can't just put a one line answer in and not tell me where to put it.
 

parry

MrExcel MVP
Joined
Aug 20, 2002
Messages
3,355
Hi, I thought you had written the code and knew some VB. OK, amend the following procedures to not run the reset code if the workbook is readonly. I think thats what your asking.

Code:
Private Sub Workbook_Open() 
If ThisWorkbook.Readonly = False Then Reset 
End Sub 
Private Sub Workbook_SheetActivate(ByVal Sh As Object) 
If ThisWorkbook.Readonly = False Then Reset 
End Sub 

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) 
If ThisWorkbook.Readonly = False Then Reset 
End Sub
 

jtbrown1955

New Member
Joined
Jan 12, 2005
Messages
40
parry said:
Hi, I thought you had written the code and knew some VB. OK, amend the following procedures to not run the reset code if the workbook is readonly. I think thats what your asking.

Code:
Private Sub Workbook_Open() 
If ThisWorkbook.Readonly = False Then Reset 
End Sub 
Private Sub Workbook_SheetActivate(ByVal Sh As Object) 
If ThisWorkbook.Readonly = False Then Reset 
End Sub 

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) 
If ThisWorkbook.Readonly = False Then Reset 
End Sub

Thank you. It (as you knew) works great. I would like to learn this myself and I am trying, but I have no resources other than the VBA help and this forum. I can learn commands, but I don't understand the relationships they have to one another or where to put them. What would be a good manual to buy?

jim
 

parry

MrExcel MVP
Joined
Aug 20, 2002
Messages
3,355
Hi Jim, have a look at MrExcels online store. I havent read it but I have heard 'VBA and Macros for Microsoft Excel' is very good.
 

Forum statistics

Threads
1,147,510
Messages
5,741,574
Members
423,668
Latest member
Audorin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top