메인 컨텐츠로 가기

특정 유휴 시간 후에 Excel 파일을 자동으로 저장하고 닫는 방법은 무엇입니까?

공유 디스크에 Excel 파일을 남겨 두는 경우와 같이 사용자가 파일을 여는 경우 다른 사용자가 통합 문서를 편집 할 수없는 경우도 있습니다. 그렇다면 다른 사람의 작업을 용이하게하기 위해 특정 유휴 시간 후에 파일을 자동으로 닫는 방법은 무엇입니까? 이 기사는 VBA 방법에 도움이 될 것입니다.

VBA 코드로 특정 유휴 시간 후에 Excel 파일 자동 저장 및 닫기


VBA 코드로 특정 유휴 시간 후에 Excel 파일 자동 저장 및 닫기

특정 유휴 시간 후에 Excel 파일을 자동 저장하고 닫으려면 다음과 같이하십시오.

1. 특정 유휴 시간이 지나면 자동으로 저장되고 닫히는 통합 문서를 엽니 다. 그런 다음 다른 + F11 열려면 함께 키 응용 프로그램 용 Microsoft Visual Basic 창.

2. 에서 응용 프로그램 용 Microsoft Visual Basic 창을 두 번 클릭하십시오. 이 워크북 오른쪽 창에서 코드 창을 엽니 다. 그런 다음 VBA 코드 아래에 복사하여 코드 창에 붙여 넣습니다. 스크린 샷보기 :

VBA 코드 1 : 특정 유휴 시간 후 Excel 파일 자동 저장 및 닫기

Dim xTime As String
Dim xWB As Workbook

Private Sub Workbook_Open()
'Updated by Extendoffice 2019/1/20
    On Error Resume Next
    xTime = Application.InputBox("Please specify the idle time:", "KuTool For Excel", "00:00:20", , , , , 2)
    Set xWB = ActiveWorkbook
    If xTime = "" Then Exit Sub
    Reset
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    On Error Resume Next
    If xTime = "" Then Exit Sub
    Reset
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    On Error Resume Next
    If xTime = "" Then Exit Sub
    Reset
End Sub

Sub Reset()
    Static xCloseTime
    If xCloseTime <> 0 Then
        ActiveWorkbook.Application.OnTime xCloseTime, "SaveWork1", , False
    End If
    xCloseTime = Now + TimeValue(xTime)
    ActiveWorkbook.Application.OnTime xCloseTime, "SaveWork1", , True
End Sub

3. 그런 다음 클릭 끼워 넣다 > 모듈을 클릭하고 아래 코드를 복사하여 모듈 창에 붙여 넣습니다. 스크린 샷보기 :

VBA 코드 2 : 특정 유휴 시간 후 Excel 파일 자동 저장 및 닫기

Sub SaveWork1()
'Updated by Extendoffice 2019/1/20
    Application.DisplayAlerts = False
    ActiveWorkbook.Save
    ActiveWorkbook.Close
    
    Application.DisplayAlerts = True
End Sub

4. 누르세요 다른 + Q 키를 동시에 닫아 응용 프로그램 용 Microsoft Visual Basic 창.

5. 클릭 입양 부모로서의 귀하의 적합성을 결정하기 위해 미국 이민국에 > 다른 이름으로 저장 > 검색. 스크린 샷보기 :

6. 에서 다른 이름으로 저장 대화 상자에서 파일을 저장할 폴더를 선택하고 파일 이름 상자에서 필요에 따라 이름을 지정한 다음 Excel 매크로 사용 통합 문서 인사말 다른 이름으로 저장 유형 드롭 다운 목록을 클릭하고 마지막으로 찜하기 단추. 스크린 샷보기 :

이제부터이 통합 문서를 열 때마다 Excel 용 Kutools 대화 상자가 나타납니다. 통합 문서를 저장하고 닫을 시간을 입력 한 다음 OK 버튼을 클릭합니다.

그리고 통합 문서는 지정된 유휴 시간 후에 자동으로 저장되고 닫힙니다. 스크린 샷보기 :

최고의 사무 생산성 도구

🤖 Kutools AI 보좌관: 다음을 기반으로 데이터 분석을 혁신합니다. 지능형 실행   |  코드 생성  |  사용자 정의 수식 만들기  |  데이터 분석 및 차트 생성  |  Kutools 기능 호출...
인기 기능: 중복 항목 찾기, 강조 표시 또는 식별   |  빈 행 삭제   |  데이터 손실 없이 열이나 셀 결합   |   수식없이 반올림 ...
슈퍼 조회: 다중 기준 VLookup    다중 값 VLookup  |   여러 시트에 걸친 VLookup   |   퍼지 조회 ....
고급 드롭다운 목록: 드롭다운 목록을 빠르게 생성   |  종속 드롭다운 목록   |  다중 선택 드롭 다운 목록 ....
열 관리자: 특정 개수의 열 추가  |  열 이동  |  Toggle 숨겨진 열의 가시성 상태  |  범위 및 열 비교 ...
특색 지어진 특징: 그리드 포커스   |  디자인보기   |   큰 수식 바    통합 문서 및 시트 관리자   |  리소스 라이브러리 (자동 텍스트)   |  날짜 선택기   |  워크 시트 결합   |  셀 암호화/해독    목록으로 이메일 보내기   |  슈퍼 필터   |   특수 필터 (굵게/기울임꼴/취소선 필터링...) ...
상위 15개 도구 세트12 본문 도구 (텍스트 추가, 문자 제거,...)   |   50+ 거래차트 유형 (Gantt 차트,...)   |   40+ 실용 방식 (생일을 기준으로 나이 계산,...)   |   19 삽입 도구 (QR 코드 삽입, 경로에서 그림 삽입,...)   |   12 매출 상승 도구 (숫자를 단어로, 환율,...)   |   7 병합 및 분할 도구 (고급 결합 행, 셀 분할,...)   |   ... 그리고 더

Excel용 Kutools로 Excel 기술을 강화하고 이전과는 전혀 다른 효율성을 경험해 보세요. Excel용 Kutools는 생산성을 높이고 시간을 절약하기 위해 300개 이상의 고급 기능을 제공합니다.  가장 필요한 기능을 얻으려면 여기를 클릭하십시오...

상품 설명


Office Tab은 Office에 탭 인터페이스를 제공하여 작업을 훨씬 쉽게 만듭니다.

  • Word, Excel, PowerPoint에서 탭 편집 및 읽기 사용, Publisher, Access, Visio 및 Project.
  • 새 창이 아닌 동일한 창의 새 탭에서 여러 문서를 열고 만듭니다.
  • 생산성을 50% 높이고 매일 수백 번의 마우스 클릭을 줄입니다!
Comments (30)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello good afternoon! I would like MSBox not to appear when opening the file. I don't want them to change the configured closing time.
This comment was minimized by the moderator on the site
The Problem is it`s a file with links and every time you start it, it will ask you if you would update it and read only mode?
This comment was minimized by the moderator on the site
Hello
Code works but if i close the file before the time runs out, It will open it again and close. how can i stop the code when i close the file manual.
This comment was minimized by the moderator on the site
Hi,

I tested the code and it did not reproduce the problem you mentioned. Can I ask which version of Excel you are using?
This comment was minimized by the moderator on the site
Hi
It is Microsoft Excel 365 MSO (Version 2308) 32 bit.
This comment was minimized by the moderator on the site
This is my Code:

Dim xTime As String
Dim xWB As Workbook

Private Sub Workbook_Open()
On Error Resume Next
xTime = "00:00:35"
Set xWB = Workbooks("Produktionsbericht - Kopie.xlsm")
If xTime = "" Then Exit Sub
Reset
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
On Error Resume Next
If xTime = "" Then Exit Sub
Reset
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
On Error Resume Next
If xTime = "" Then Exit Sub
Reset
End Sub

Sub Reset()
Static xCloseTime
If xCloseTime <> 0 Then
xWB.Application.OnTime xCloseTime, "SaveWork1", , False
End If
xCloseTime = Now + TimeValue(xTime)
xWB.Application.OnTime xCloseTime, "SaveWork1", , True
End Sub
This comment was minimized by the moderator on the site
Hello
All works at my file but i have a new Problem.
If i close the file before the time runs out, it will open it again and close it when the time runs out.
Can i stop the VBA Code when i close the File myself?
This comment was minimized by the moderator on the site
Code is not working if the module is protected, is there any way to get the code run if module is protected.
This comment was minimized by the moderator on the site
Hi Chinna,

If the module is protected, the code is hidden and cannot be run. Sorry for the inconvenience.
This comment was minimized by the moderator on the site
Perdonen, si se pudiera modificar el código o adaptarlo para que reaccione con formularios (UserForm), porque solo reacciona al estar activo en las celdas pero no en los formularios, gracias
This comment was minimized by the moderator on the site
Hi Moises Peraza,
UserForm does not affect the use of the VBA code. Can you describe the problem you encountered more clearly.
This comment was minimized by the moderator on the site
Gracias por responder, el inconveniente que tengo es: le pongo de tiempo de inactividad 2 min. En el momento de trabajar con formularios (ingresar información del cliente), pasado ese tiempo me cierra o me tira el mensaje que se cerrara, espero darme a entender
This comment was minimized by the moderator on the site
Hi mister, how to view the countdown?
This comment was minimized by the moderator on the site
Hi mister, how to view the countdown?
This comment was minimized by the moderator on the site
(Sigh.)
Have a look at the code.
If you put this VBA into Excel001.xlsm, but, when the timeout occurs, you have Excel002.xlsm as the "active" workbook, then it's actually going to close THAT Excel file, rather than the one you've put the VBA into.
This comment was minimized by the moderator on the site
look below, Mark's comment : "I would recommend identifying the workbook with the workbook file name. This would allow the users to have multiple workbooks open and closing out only the specific workbook that needs to have the time lock.

Suggestion: Set xwb = Workbooks("<file name>")
instead of: Set xwb = ActiveWorkbook

Also, replace all references to "ActiveWorkbook" to the Xwb in the module

Great code otherwise."
This comment was minimized by the moderator on the site
Hi. I need to set my shared spreadsheet on the office network to auto save and close when I'm done with it for the day. Only my boss and I are supposed to make and save changes, but several managers view it daily.
I need to be able to have it auto save for the two of us, while not saving for other users. Is this possible? Can I set the macro to work only for us? Or will it effect everyone?
I know how to protect the sheet, but I can't do that, because they want to be able to make some temporary changes from time to time. I just need to be able restrict auto save to specific users.
This comment was minimized by the moderator on the site
Is there a way to change this so it prompts the user to save/close the file, instead of automatically saving and closing the file?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations