please help, read only is overwriting file

jtbrown1955

New Member
Joined
Jan 12, 2005
Messages
40
I have a timer set to close a workbook automatically after it has been left open on a network and is no longer active. The second copy opened (of course) is a read only. When the read only book closes it prompts the user "There is already a file with that name, do you want to save over that file?" If the user says yes, it WILL overwrite the file. This is a "read only copy". Without the following code, the read only copy will act normal and won't allow you to save over the file. Here is the code that I got off this forum. Thanks! I need something added to it, to tame the read only copy.

This is under 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 under Module1
Sub Reset()
Static SchedSave
If SchedSave <> 0 Then
Application.OnTime SchedSave, "SaveWork", , False
End If
SchedSave = Now + TimeValue("00:10:00") ' 10 minutes
Application.OnTime SchedSave, "SaveWork", , True
End Sub
Sub SaveWork()
ThisWorkbook.Save
ThisWorkbook.Close
End Sub



Thanks

Jim
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Perhaps the following line in the approprate place is what you are looking for:

<font face=Courier New>
If Application.ThisWorkbook.ReadOnly = <SPAN style="color:#00007F">True</SPAN> Then Application.ThisWorkbook.Saved = <SPAN style="color:#00007F">True</SPAN>
</FONT>

This should prevent the save prompt altogether for the read-only version.
 
Upvote 0
biztekjim said:
Perhaps the following line in the approprate place is what you are looking for:

<font face=Courier New>
If Application.ThisWorkbook.ReadOnly = <SPAN style="color:#00007F">True</SPAN> Then Application.ThisWorkbook.Saved = <SPAN style="color:#00007F">True</SPAN>
</FONT>

This should prevent the save prompt altogether for the read-only version.

I put that line in so the code now looks like this:

Sub SaveWork()
If Application.ThisWorkbook.ReadOnly = True Then
Application.ThisWorkbook.Saved = True
End If
ThisWorkbook.Save
ThisWorkbook.Close
End Sub

When original closes, everything is fien. When the Read Only closes, I get a Run Time Error 1004 and the Debug highlights the "ThisWorkbook.Save" line. What did I do wrong?

Jim
 
Upvote 0
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> SaveWork()
<SPAN style="color:#00007F">If</SPAN> Application.ThisWorkbook.ReadOnly = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN>
    Application.ThisWorkbook.Saved = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">Else</SPAN>
    ThisWorkbook.Save
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
ThisWorkbook.Close
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
biztekjim said:
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> SaveWork()
<SPAN style="color:#00007F">If</SPAN> Application.ThisWorkbook.ReadOnly = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN>
    Application.ThisWorkbook.Saved = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">Else</SPAN>
    ThisWorkbook.Save
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
ThisWorkbook.Close
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

OK, so you gotta hold some people's hands. When I put the Else statement in and moved the lines where they should be, it worked. Thank you.

jim
 
Upvote 0

Forum statistics

Threads
1,202,988
Messages
6,052,944
Members
444,619
Latest member
Pawar537

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