Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Owner2229
in reply to: francesco.dinh

Here's the code with a document check to prevent an attempt to save closed document.

It will keep reseting until you (re)open new(another) document.

 

Sub Main()
	Dim Thread1 As New System.Threading.Thread(AddressOf AutoSave)
	Thread1.Start()
End Sub

Sub AutoSave()
	Dim AST As Integer = 0
	While True
		If ThisDoc IsNot Nothing Then
			If AST >= 15 Then '15 minutes
				AST = 0
				Dim SF As DialogResult = MessageBox.Show("Do you want to save?", "Autosave", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
				If SF = vbYes And ThisDoc IsNot Nothing Then
					ThisDoc.Save()
				End If
			Else
				AST += 1
			End If
		Else
			AST = 0
		End If
		System.Threading.Thread.Sleep(60000) '1 minute = 60000 ms
	End While
End Sub
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods