auto close macro

vbnoob

Board Regular
Joined
Oct 22, 2008
Messages
67
Hi all,

I have got the following Macro so a workbook does not stay open on somebodies computer. However even after it closes it reopens and prompts me to enable macros and when I do it closes again. I thought I had put in another Macro that stops that as soon as the workbook is closed. Could somebody tell me why this is not working?

The following is in the "thisworkbook" object.
Code:
Private Sub Workbook_Open()
Sheets("pp").Select
   Range("G5:L5").Select
dtmSchedule = Now + TimeValue("01:00:00")
Application.OnTime dtmSchedule, "TimeOut"
If ThisWorkbook.ReadOnly Then
    MsgBox ("The file is currently being used by another user, please contact them to ensure they have not left the file open.")
    ThisWorkbook.Close SaveChanges:=False
End If
With Worksheets("PP")
    .Protect Password:="bargy", userinterfaceonly:=True
    .EnableOutlining = True
End With
End Sub
    
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
   On Error Resume Next
   Application.OnTime dtmSchedule, "TimeOut", , False
End Sub

In a serperate Module.
Code:
Sub TimeOut()
   ThisWorkbook.Close SaveChanges:=True
End Sub

Your help would be greatly appreciated.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
It does not answer my question though as the macro already works.

However it still runs after the book is closed so will open back up after it has been closed to then close again straight away. I had a bit of code in there that worked on close to stop the other macro but that does not seem to be working.

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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