PDA

View Full Version : Workbook that forces users to enable Macros and automatically closes after some time



xdciroo
10-14-2017, 12:15 PM
Hi,

so I made a Workbook that does 2 things:
1. It forces users to enable Macros and
2. It automatically closes after being inactive for a defined amount of time

The idea behind this is that only one user at the time would be able to use this file and that the file will automatically close after a certain time of being inactive. This will be useful if someone forgets to close a Workbook after using it (which can occur really often).

I found all of necessary Macros on the web. So what I basically did was that I joined all of these Macros in one Workbook (see attachment)

I ran into one problem. That is, that the workbook still wants a conformation for saving before closing. This prevents the closure of the workbook. Is there a way I could adjust the Macros so that this problem wont occur anymore.

Thanks in advance and Kind Regards,

Ciril

6StringJazzer
10-14-2017, 05:55 PM
It is not clear what you are expecting since you have explicit code in Workbook_BeforeClose to prompt the user to save changes if there are unsaved changes. If you want to prevent your own code from prompting the user then simply save before closing in Module1:



Sub CloseSave()


If Timer - TheTime > 30 Then ' po 30ih sekundah bi se moral izklopit
ThisWorkbook.Save '''' ADDED LINE
ThisWorkbook.Close SaveChanges:=True
' ThisWorkbook.Close SaveChanges:=False
End If


End Sub

xdciroo
10-14-2017, 11:14 PM
It is not clear what you are expecting since you have explicit code in Workbook_BeforeClose to prompt the user to save changes if there are unsaved changes. If you want to prevent your own code from prompting the user then simply save before closing in Module1:



Sub CloseSave()


If Timer - TheTime > 30 Then ' po 30ih sekundah bi se moral izklopit
ThisWorkbook.Save '''' ADDED LINE
ThisWorkbook.Close SaveChanges:=True
' ThisWorkbook.Close SaveChanges:=False
End If


End Sub


Thank you :) Simple, but great solution. :D

6StringJazzer
10-15-2017, 06:06 AM
You're welcome! Feel free to post back if you find it's not quite what you needed.