मुख्य सामग्री पर जाएं

एक निश्चित समय तक निष्क्रियता के बाद कार्यपुस्तिका को कैसे सहेजें और बंद करें?

लेखक: रवि अंतिम संशोधित: 2016-08-22

कुछ समय में, जब आप लंबे समय तक अन्य मामलों में व्यस्त रहते हैं तो आप गलती से किसी कार्यपुस्तिका को बंद कर सकते हैं, जिससे कार्यपुस्तिका में कुछ महत्वपूर्ण डेटा खो सकता है। यदि आपने कार्यपुस्तिका को एक निश्चित समय के लिए निष्क्रिय कर दिया है तो क्या उसे स्वचालित रूप से सहेजने और बंद करने की कोई तरकीब है?

वीबीए के साथ एक निश्चित समय के लिए निष्क्रियता के बाद कार्यपुस्तिका को स्वतः सहेजें और बंद करें

तीर नीला दायां बुलबुला वीबीए के साथ एक निश्चित समय के लिए निष्क्रियता के बाद कार्यपुस्तिका को स्वतः सहेजें और बंद करें

इस समस्या को हल करने के लिए एक्सेल में कोई अंतर्निहित फ़ंक्शन नहीं है, लेकिन मैं एक मैक्रो कोड पेश कर सकता हूं जो एक निश्चित समय में निष्क्रियता के बाद कार्यपुस्तिका को सहेजने और बंद करने में आपकी सहायता कर सकता है।

1. जिस कार्यपुस्तिका को आप स्वचालित रूप से सहेजना चाहते हैं उसे सक्षम करें और कुछ सेकंड के लिए निष्क्रियता के बाद बंद करें, और दबाएँ ऑल्ट + F11 खोलने के लिए चाबी अनुप्रयोगों के लिए माइक्रोसॉफ्ट विज़ुअल बेसिक खिड़की.

2। क्लिक करें सम्मिलित करें > मॉड्यूल बनाने के लिए मॉड्यूल स्क्रिप्ट, और उसमें नीचे दिया गया कोड पेस्ट करें। स्क्रीनशॉट देखें:

Dim CloseTime As Date
Sub TimeSetting()
    CloseTime = Now + TimeValue("00:00:15")
    On Error Resume Next
    Application.OnTime EarliestTime:=CloseTime, _
      Procedure:="SavedAndClose", Schedule:=True
End Sub
Sub TimeStop()
    On Error Resume Next
    Application.OnTime EarliestTime:=CloseTime, _
      Procedure:="SavedAndClose", Schedule:=False
 End Sub
Sub SavedAndClose()
    ActiveWorkbook.Close Savechanges:=True
End Sub

 

निष्क्रियता के बाद दस्तावेज़ सहेजें कार्यपुस्तिका बंद करें 1

3. फिर में प्रोजेक्ट एक्सप्लोरर फलक, डबल क्लिक करें यह कार्यपुस्तिका, और नीचे दिए गए कोड को अगली स्क्रिप्ट में पेस्ट करें। स्क्रीनशॉट देखें:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Call TimeStop
End Sub

Private Sub Workbook_Open()
    Call TimeSetting
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
   Call TimeStop
   Call TimeSetting
End Sub

 

निष्क्रियता के बाद दस्तावेज़ सहेजें कार्यपुस्तिका बंद करें 2

4. चरण 2 में आपके द्वारा डाले गए मॉड्यूल पर डबल क्लिक करें और दबाएँ F5 कोड चलाने की कुंजी. स्क्रीनशॉट देखें:
निष्क्रियता के बाद दस्तावेज़ सहेजें कार्यपुस्तिका बंद करें 3

5. फिर 15 सेकंड के बाद आपको वर्कबुक सेव करने की याद दिलाने के लिए एक डायलॉग पॉप होता है, उस पर क्लिक करें हाँ कार्यपुस्तिका को सहेजने और बंद करने के लिए.
निष्क्रियता के बाद दस्तावेज़ सहेजें कार्यपुस्तिका बंद करें 4

सुझाव:

(1) पहले कोड में, आप इस स्ट्रिंग में निष्क्रियता समय को अन्य में बदल सकते हैं: अभी + टाइमवैल्यू("00:00:15")

(2) यदि आपने पहले कभी कार्यपुस्तिका सहेजी नहीं है इस रूप में सहेजें सबसे पहले डायलॉग बॉक्स आएगा और आपसे इसे सेव करने के लिए कहेगा।
निष्क्रियता के बाद दस्तावेज़ सहेजें कार्यपुस्तिका बंद करें 5


अच्छा वर्कशीट को सुरक्षित रखें

एक्सेल के लिए कुटूल वर्कशीट को सुरक्षित रखें फ़ंक्शन एक साथ कई शीटों या संपूर्ण कार्यपुस्तिका को शीघ्रता से सुरक्षित कर सकता है।
दस्तावेज़ एकाधिक कार्यपत्रकों की सुरक्षा करता है

सर्वोत्तम कार्यालय उत्पादकता उपकरण

🤖 कुटूल्स एआई सहयोगी: निम्न के आधार पर डेटा विश्लेषण में क्रांति लाएं: बुद्धिमान निष्पादन   |  कोड जनरेट करें  |  कस्टम फ़ॉर्मूले बनाएं  |  डेटा का विश्लेषण करें और चार्ट बनाएं  |  कुटूल फ़ंक्शंस का आह्वान करें...
लोकप्रिय सुविधाएँ: डुप्लिकेट ढूंढें, हाइलाइट करें या पहचानें   |  रिक्त पंक्तियाँ हटाएँ   |  डेटा खोए बिना कॉलम या सेल को संयोजित करें   |   फॉर्मूला के बिना गोल ...
सुपर लुकअप: एकाधिक मानदंड VLookup    मल्टीपल वैल्यू वीलुकअप  |   अनेक शीटों में VLookup   |   फजी लुकअप ....
उन्नत ड्रॉप-डाउन सूची: शीघ्रता से ड्रॉप डाउन सूची बनाएं   |  आश्रित ड्रॉप डाउन सूची   |  बहु-चयन ड्रॉप डाउन सूची ....
स्तम्भ प्रबंधक: कॉलमों की एक विशिष्ट संख्या जोड़ें  |  कॉलम ले जाएँ  |  छिपे हुए कॉलम की दृश्यता स्थिति टॉगल करें  |  रेंज और कॉलम की तुलना करें ...
फीचर्ड फीचर्स: ग्रिड फोकस   |  डिजाइन देखें   |   बड़ा फॉर्मूला बार    कार्यपुस्तिका एवं शीट प्रबंधक   |  संसाधन लाइब्रेरी (ऑटो टेक्स्ट)   |  खजूर बीनने वाला   |  कार्यपत्रकों को संयोजित करें   |  एन्क्रिप्ट/डिक्रिप्ट सेल    सूची के अनुसार ईमेल भेजें   |  सुपर फ़िल्टर   |   विशेष फ़िल्टर (फ़िल्टर बोल्ड/इटैलिक/स्ट्राइकथ्रू...) ...
शीर्ष 15 टूलसेट12 टेक्स्ट टूल्स (पाठ जोड़ें, अक्षर हटाएँ, ...)   |   50 + चार्ट प्रकार (गैन्ट चार्ट, ...)   |   40+ प्रैक्टिकल सूत्र (जन्मदिन के आधार पर आयु की गणना करें, ...)   |   19 निवेशन टूल्स (QR कोड डालें, पथ से चित्र सम्मिलित करें, ...)   |   12 रूपांतरण टूल्स (शब्दों को संख्याएँ, मुद्रा रूपांतरण, ...)   |   7 विलय और विभाजन टूल्स (उन्नत संयोजन पंक्तियाँ, विभाजन कोशिकाओं, ...)   |   ... और अधिक

एक्सेल के लिए कुटूल के साथ अपने एक्सेल कौशल को सुपरचार्ज करें, और पहले जैसी दक्षता का अनुभव करें। एक्सेल के लिए कुटूल उत्पादकता बढ़ाने और समय बचाने के लिए 300 से अधिक उन्नत सुविधाएँ प्रदान करता है।  वह सुविधा प्राप्त करने के लिए यहां क्लिक करें जिसकी आपको सबसे अधिक आवश्यकता है...

Description


ऑफिस टैब ऑफिस में टैब्ड इंटरफ़ेस लाता है, और आपके काम को बहुत आसान बनाता है

  • Word, Excel, PowerPoint में टैब्ड संपादन और रीडिंग सक्षम करें, प्रकाशक, एक्सेस, विसियो और प्रोजेक्ट।
  • नई विंडो के बजाय एक ही विंडो के नए टैब में एकाधिक दस्तावेज़ खोलें और बनाएं।
  • आपकी उत्पादकता 50% बढ़ जाती है, और आपके लिए हर दिन सैकड़ों माउस क्लिक कम हो जाते हैं!
Comments (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
When I don't want to edit and I just want to consult, the file still closes. It shouldn't close. Should restart counting when I select cells. What is the solution?
This comment was minimized by the moderator on the site
When I don't want to edit and I just want to consult, the file still closes. It shouldn't close. Should restart counting when I select cells. What is the solution?
This comment was minimized by the moderator on the site
This is great. Any tips on adding a popup message box that will warn the user the sheet is about to close and give them the option to reset the timer?
This comment was minimized by the moderator on the site
I'm not sure what happened but this solution no longer works. Here is the fix to this solution that worked for me:

````
Dim resetCount As Long

Public Sub Workbook_Open()
On Error Resume Next
Set xWB = ThisWorkbook
resetCount = 0
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)On Error Resume Next
Reset
End Sub

Sub Reset()On Error Resume Next
Static xCloseTime
If resetCount <> 0 Then
ThisWorkbook.Application.OnTime xCloseTime, "SaveWork1", Schedule:=False
resetCount = resetCount + 1
xCloseTime = DateAdd("n", 15, Now)
ThisWorkbook.Application.OnTime xCloseTime, "SaveWork1", Schedule:=True

Else
resetCount = resetCount + 1
xCloseTime = DateAdd("n", 15, Now)
ThisWorkbook.Application.OnTime xCloseTime, "SaveWork1", Schedule:=True
End If
End Sub
````
This is using the same SaveWork1 As:
````Sub SaveWork1()
Application.DisplayAlerts = False
ThisWorkbook.Save
ThisWorkbook.Close

Application.DisplayAlerts = True
End Sub

````
This comment was minimized by the moderator on the site
If you are working in a separate workbook at the point where close time is reached then it will close that workbook and not the inactive one. This can be solved by adjusting the code to: - corrected and tested from the below comment - use this code:

Enter into "This Workbook"

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call TimeStop
End Sub
Private Sub Workbook_Open()
Call TimeSetting
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Call TimeStop
Call TimeSetting
End Sub


Enter into "module":

Dim CloseTime As Date
Sub TimeSetting()
CloseTime = Now + TimeValue("00:10:00")
On Error Resume Next
Application.OnTime EarliestTime:=CloseTime, _
Procedure:="SavedAndClose", Schedule:=True
End Sub
Sub TimeStop()
On Error Resume Next
Application.OnTime EarliestTime:=CloseTime, _
Procedure:="SavedAndClose", Schedule:=False
End Sub
Sub SavedAndClose()
ThisWorkbook.Close Savechanges:=True
End Sub


you can change the time setting by changing CloseTime = Now + TimeValue("00:10:00") - this is set to 10 minutes, change the("00:10:00") to whatever time you want and it works.
This comment was minimized by the moderator on the site
hi i want insert this code to an other code like expiration code with this code how i can do....?
code is...following
Private Sub Workbook_Open()

Dim exdate As Date
Dim i As Integer

'modify values for expiration date here !!!
anul = 2019 'year
luna = 5 'month
ziua = 16 'day

exdate = DateSerial(anul, luna, ziua)

If Date > exdate Then
MsgBox ("The application " & ThisWorkbook.Name & " has expired !" & vbNewLine & vbNewLine _
& "Expiration set up date is: " & exdate & " :)" & vbNewLine & vbNewLine _
& "Contact Administrator to renew the version !"), vbCritical, ThisWorkbook.Name

expired_file = ThisWorkbook.Path & "\" & ThisWorkbook.Name

On Error GoTo ErrorHandler
With Workbooks(ThisWorkbook.Name)
If .Path <> "" Then

.Saved = True
.ChangeFileAccess xlReadOnly

Kill expired_file

'get the name of the addin if it is addin and unistall addin
If Application.Version >= 12 Then
i = 5
Else: i = 4
End If

If Right(ThisWorkbook.Name, i) = ".xlam" Or Right(ThisWorkbook.Name, i) = ".xla" Then
wbName = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - i)
'uninstall addin if it is installed
If AddIns(wbName).Installed Then
AddIns(wbName).Installed = False
End If
End If

.Close

End If
End With

Exit Sub

End If

'MsgBox ("You have " & exdate - Date & "Days left")
Exit Sub

ErrorHandler:
MsgBox "Fail to delete file.. "
Exit Sub

End Sub
This comment was minimized by the moderator on the site
brilliant thanks
This comment was minimized by the moderator on the site
If you are working in a separate workbook at the point where close time is reached then it will close that workbook and not the inactive one. This can be solved by adjusting the code to:

Dim CloseTime As Date
Dim WKB As String
Sub TimeSetting()
WKB = ActiveWorkbook.Name
CloseTime = Now + TimeValue("00:00:15")
On Error Resume Next
Application.OnTime EarliestTime:=CloseTime, _
Procedure:="SavedAndClose", Schedule:=True
End Sub
Sub TimeStop()
On Error Resume Next
Application.OnTime EarliestTime:=CloseTime, _
Procedure:="SavedAndClose", Schedule:=False
End Sub
Sub SavedAndClose()
Workbooks(WKB).Close Savechanges:=True
End Sub
This comment was minimized by the moderator on the site
I sometimes run into a "Running time Error" when open the workbook that has this code built into it. Anyway to write this code better for it to be more stable?
This comment was minimized by the moderator on the site
I noticed the same thing. And found the same solution :-)
This comment was minimized by the moderator on the site
The above code is not working when a cell is active. That is

1. enter a value in the cell (don't press Enter or tab)

2. minimize the excel.

In this case the code is not working.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations