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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
ThisWorkbook.ReadOnly will return true if the book is read only, and false if its not.
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,517
Members
448,968
Latest member
Ajax40

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
Back
Top