Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-12-2024, 04:04 AM
Octochimp Octochimp is offline Close inactive document Windows 11 Close inactive document Office 2021
Novice
 
Join Date: Sep 2024
Posts: 1
Octochimp is on a distinguished road
Default

this took way too long to figure out, but it is remarkably simple in hindsight, so here it is

in VBA in the main ThisDocument page put :

Option Explicit


Private Sub Document_Open()
CheckTime
End Sub

then, add a module, containing the following :

Option Explicit
Dim PreviousContent As String
Sub CheckTime()
PreviousContent = ActiveDocument.Content
Application.OnTime When:=Now + TimeValue("00:10:00"), _
Name:="DoCompare"
End Sub
Sub DoCompare()
If ActiveDocument.Content = PreviousContent Then
'if no changes after 10 minutes, save then close the document
ActiveDocument.Save
ActiveDocument.Close
Else
CheckTime
End If
End Sub
Reply With Quote
  #2  
Old 09-12-2024, 08:40 AM
Italophile Italophile is offline Close inactive document Windows 11 Close inactive document Office 2021
Expert
 
Join Date: Mar 2022
Posts: 552
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Quote:
Originally Posted by Octochimp View Post
this took way too long to figure out, but it is remarkably simple in hindsight, so here it is

in VBA in the main ThisDocument page put :

Option Explicit
Private Sub Document_Open()
CheckTime
End Sub

then, add a module, containing the following :

Option Explicit
Dim PreviousContent As String
Sub CheckTime()
PreviousContent = ActiveDocument.Content
Application.OnTime When:=Now + TimeValue("00:10:00"), _
Name:="DoCompare"
End Sub
Sub DoCompare()
If ActiveDocument.Content = PreviousContent Then
'if no changes after 10 minutes, save then close the document
ActiveDocument.Save
ActiveDocument.Close
Else
CheckTime
End If
End Sub
Even simpler is to check ActiveDocument.Saved: Document.Saved property (Word) | Microsoft Learn

A simplistic comparison of two text strings ignores the fact that the author may have spent time carefully applying formatting to the text. That effort would be lost.

Last edited by Italophile; 09-12-2024 at 11:29 PM.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to dectect if close document and now no document open skarden Word VBA 2 10-24-2022 07:03 AM
Close inactive document Close Document Without Saving Prompt Joe528 Word 3 10-08-2021 06:12 PM
Document close if/then/else error eduzs Word VBA 1 01-02-2021 05:56 AM
Save and Close powerpoint if it is inactive MetteGaga PowerPoint 0 04-16-2015 05:14 AM
Prompt when close the document ubns Word 15 04-29-2012 10:07 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:54 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft