메인 컨텐츠로 가기

타임 스탬프와 함께 Excel 파일 이름을 저장하는 방법은 무엇입니까?

현재 타임 스탬프로 Excel 파일을 저장해 본 적이 있습니까? 이 기사는 그것을 달성하는 방법을 보여줄 것입니다.

VBA 코드로 타임 스탬프와 함께 Excel 파일 이름 저장


화살표 블루 오른쪽 거품 VBA 코드로 타임 스탬프와 함께 Excel 파일 이름 저장

아래 VBA 코드를 실행하여 타임 스탬프와 함께 Excel 파일 이름을 저장할 수 있습니다. 다음과 같이하십시오.

1. 통합 문서에서 현재 타임 스탬프로 이름을 지정해야합니다. 다른 + F11 동시에 열려면 키 Microsoft Visual Basic for Applications 창.

2. 에서 응용 프로그램 용 Microsoft Visual Basic 창을 클릭하십시오 끼워 넣다 > 모듈. 그런 다음 아래 VBA 코드를 암호 창문. 스크린 샷보기 :

VBA 코드: Excel 파일 이름을 타임스탬프로 저장(파일 이름을 타임스탬프로 대체)

Sub SaveAsFilenameWithTimestamp()
'Updated by Extendoffice 20191223
Dim xWb As Workbook
Dim xStrDate As String
Dim xFileName As Variant
Dim xFileDlg As FileDialog
Dim i As Variant
Application.DisplayAlerts = False
Set xWb = ActiveWorkbook
xStrDate = Format(Now, "yyyy-mm-dd hh-mm-ss")
If Right(xWb.Name, 4) = "xlsm" Then
  xFileName = Application.GetSaveAsFilename(xStrDate, "Excel Macro-Enabled Workbook (*.xlsm),*.xlsm")
Else
  xFileName = Application.GetSaveAsFilename(xStrDate, "Excel Workbook (*.xlsx),*.xlsx")
End If
If xFileName = False Then
Else
  xWb.SaveAs (xFileName)
End If
Application.DisplayAlerts = True
End Sub

3. 누르세요 F5 코드를 실행하는 키입니다. 그 다음에 다른 이름으로 저장 대화 상자가 나타나면 파일 이름 상자에 표시된 타임 스탬프를 볼 수 있습니다. 이 파일을 저장할 위치를 지정한 다음 찜하기 단추. 스크린 샷보기 :

노트:

1. 새로 생성 된 엑셀 파일은 현재 타임 스탬프의 이름으로 직접 저장됩니다.

2. 이미 존재하는 Excel 파일의 경우 원래 파일 이름이 타임 스탬프로 대체됩니다.

교체하는 대신 원본 파일 이름 뒤에 타임스탬프만 추가하려면 아래 VBA 코드를 적용하세요.

VBA 코드: 타임스탬프와 함께 Excel 파일 이름 저장(타임스탬프 뒤에 원본 파일 이름 삽입)

Sub AddTimestampToFileName()
'Updated by Extendoffice 20191223
Dim xWb As Workbook
Dim xStr As String
Dim xStrOldName As String
Dim xStrDate As String
Dim xFileName As Variant
Dim xFileDlg As FileDialog
Dim i As Variant
Application.DisplayAlerts = False
Set xWb = ActiveWorkbook
xStrOldName = xWb.Name
xStr = Left(xStrOldName, Len(xStrOldName) - 5)
xStrDate = Format(Now, "yyyy-mm-dd hh-mm-ss")
If Right(xStrOldName, 4) = "xlsm" Then
  xFileName = Application.GetSaveAsFilename(xStr & " " & xStrDate, "Excel Macro-Enabled Workbook (*.xlsm),*.xlsm")
Else
  xFileName = Application.GetSaveAsFilename(xStr & " " & xStrDate, "Excel Workbook (*.xlsx),*.xlsx")
End If
If xFileName = False Then
Else
  xWb.SaveAs (xFileName)
End If
Application.DisplayAlerts = True
End Sub

화살표 블루 오른쪽 거품관련 기사:

최고의 사무 생산성 도구

🤖 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 (12)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
To whom it may concern,
I try to implied your code "VBA code: Save an Excel filename with timestamp (Insert timestamp within original file name)" at https://www.extendoffice.com/documents/excel/4413-excel-timestamp-filename.html. BUT it stop at new file name with timestamp Save As dialogue box. If I want to auto save continuous after Save As shown dialogue box, Close all workbook and close application. What VBA code you recommend to end this job? Please help.

Please answer me at misterxyz123@gmail
This comment was minimized by the moderator on the site
Hi Mr.X,
After running the code, all opened workbooks (except for the currently using workbook) are saved as new files with timestamp followed by the original file name then closed automatically. Please give it a try. Thank you.
Please specify a folder to save the files in this line: xPath = "C:\Users\Win10x64Test\Desktop\file with timestamp\"
Sub AddTimestampToFileName()
    'Updated by Extendoffice 20220826
    Dim xWb As Workbook
    Dim xStr As String
    Dim xPath As String
    Dim xStrDate As String
    Dim xFileName As String
    Application.DisplayAlerts = False
    
    
    xPath = "C:\Users\Win10x64Test\Desktop\file with timestamp\"
    xFileName = ActiveWorkbook.Name
    xStrDate = " " & Format(Now, "yyyy-mm-dd hh-mm-ss")
    For Each xWb In Workbooks
        If xWb.Name <> xFileName Then
            If Dir(xWb.FullName) <> "" Then
                xStr = Left(xWb.Name, InStrRev(xWb.Name, ".") - 1)
                xWb.SaveAs Filename:=xPath & Replace(xWb.Name, xStr, xStr & xStrDate)
            Else
                xWb.SaveAs Filename:=xPath & xWb.Name & xStrDate & ".xlsx"
            End If
        xWb.Close
        End If
    Next
    
    xStr = Left(xFileName, InStrRev(xFileName, ".") - 1)
    ActiveWorkbook.SaveAs Filename:=xPath & Replace(xFileName, xStr, xStr & xStrDate)
    Application.DisplayAlerts = True
    
End Sub
This comment was minimized by the moderator on the site
Is it possible to embed the code and tell it where to save the file rather than individually select the save path each time?
This comment was minimized by the moderator on the site
This works except when the user presses the cancel button, it still creates a file called "false".
This comment was minimized by the moderator on the site
Hi Jason,
Thank you for reminding me. The codes are updated.
This comment was minimized by the moderator on the site
Would it be possible to modify it to remove the previous timestamp and save it as in the same directory?
This comment was minimized by the moderator on the site
Good day,
Sorry can't help you with that.
This comment was minimized by the moderator on the site
You can't save files with : within the filename, if you change this to nbre = Format(Now, "yyyy-mm-dd hh-mm")
This comment was minimized by the moderator on the site
Dear Nathan,
The below VBA code can help to add the timestamp within the filename.

Sub test()
Dim xWb As Workbook
Dim xStr As String
Dim xStrOldName As String
Dim xStrDate As String
Dim xFileName As String
Dim xFileDlg As FileDialog
Dim i As Variant
Application.DisplayAlerts = False
Set xWb = ActiveWorkbook
xStrOldName = xWb.Name
xStr = Left(xStrOldName, Len(xStrOldName) - 5)
xStrDate = Format(Now, "yyyy-mm-dd hh-mm-ss")
If Right(xStrOldName, 4) = "xlsm" Then
xFileName = Application.GetSaveAsFilename(xStr & " " & xStrDate, "Excel Macro-Enabled Workbook (*.xlsm),*.xlsm")
Else
xFileName = Application.GetSaveAsFilename(xStr & " " & xStrDate, "Excel Workbook (*.xlsx),*.xlsx")
End If
xWb.SaveAs (xFileName)
Application.DisplayAlerts = True
End Sub
This comment was minimized by the moderator on the site
I have this below, which works perfect to save file with date stamp, BUT would not work if change to this to add time-> nbre = Format(Now, "yyyy-mm-dd hh:mm")


nbre = Format(Now, "yyyy-mm-dd")


Application.DisplayAlerts = False


ChDir "T:\Distribution Center"
ActiveWorkbook.SaveAs Filename:="T:\Distribution Center\2. BACKLOG\DC BACKLOG " + nbre + ".xlsx", FileFormat _
:=xlOpenXMLWorkbook, WriteResPassword:="****", CreateBackup:=False



Can you please help what is missning???....
This comment was minimized by the moderator on the site
You cannot use the character ":" in file names
This comment was minimized by the moderator on the site
Is there a version of this that works for Word documents?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations