انتقل إلى المحتوى الرئيسي

كيف تحفظ اسم ملف Excel مع الطابع الزمني؟

هل سبق لك أن حاولت حفظ ملف Excel بالطابع الزمني الحالي؟ ستوضح لك هذه المقالة طريقة تحقيق ذلك.

احفظ اسم ملف Excel مع طابع زمني برمز VBA


السهم الأزرق الحق فقاعة احفظ اسم ملف Excel مع طابع زمني برمز VBA

يمكنك تشغيل كود VBA أدناه لحفظ اسم ملف Excel مع الطابع الزمني. الرجاء القيام بما يلي.

1. في المصنف الذي تريد تسميته بالطابع الزمني الحالي ، يرجى الضغط على قديم + F11 مفاتيح في نفس الوقت لفتح نافذة ميكروسوفت فيسوال باسيك للتطبيقات.

2. في ال ميكروسوفت فيسوال باسيك للتطبيقات نافذة ، الرجاء الضغط إدراج > وحدة. ثم انسخ رمز 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. سيتم حفظ ملف Excel الذي تم إنشاؤه حديثًا باسم الطابع الزمني الحالي مباشرةً.

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 عبر أوراق متعددة   |   بحث غامض ....
قائمة منسدلة متقدمة: إنشاء القائمة المنسدلة بسرعة   |  القائمة المنسدلة التابعة   |  قائمة منسدلة متعددة التحديد ....
مدير العمود: إضافة عدد محدد من الأعمدة  |  نقل الأعمدة  |  تبديل حالة رؤية الأعمدة المخفية  |  مقارنة النطاقات والأعمدة 
الميزات المميزة: التركيز على الشبكة   |  عرض تصميم   |   شريط الفورمولا الكبير    مدير المصنفات والأوراق   |  مكتبة الموارد (النص السيارات)   |  منتقي التاريخ   |  اجمع أوراق العمل   |  تشفير/فك تشفير الخلايا    إرسال رسائل البريد الإلكتروني عن طريق القائمة   |  سوبر تصفية   |   مرشح خاص (تصفية غامق / مائل / يتوسطه خط ...) ...
أفضل 15 مجموعة أدوات12 نص الأدوات (إضافة نص, إزالة الأحرف، ...)   |   +50 رسم الأنواع (مخطط جانت، ...)   |   40+ عملي الصيغ (احسب العمر على أساس تاريخ الميلاد، ...)   |   19 إدخال الأدوات (أدخل رمز الاستجابة السريعة, إدراج صورة من المسار، ...)   |   12 تحويل الأدوات (أرقام إلى كلمات, نتيجة تحويل عملة، ...)   |   7 دمج وتقسيم الأدوات (الجمع بين الصفوف المتقدمة, تقسيم الخلايا، ...)   |   ... و اكثر

عزز مهاراتك في Excel باستخدام Kutools for Excel، واختبر كفاءة لم يسبق لها مثيل. يقدم Kutools for Excel أكثر من 300 ميزة متقدمة لتعزيز الإنتاجية وتوفير الوقت.  انقر هنا للحصول على الميزة التي تحتاجها أكثر...

الوصف


يجلب Office Tab الواجهة المبوبة إلى Office ، ويجعل عملك أسهل بكثير

  • تمكين التحرير والقراءة المبوبة في Word و Excel و PowerPointوالناشر والوصول و Visio والمشروع.
  • فتح وإنشاء مستندات متعددة في علامات تبويب جديدة من نفس النافذة ، بدلاً من النوافذ الجديدة.
  • يزيد من إنتاجيتك بنسبة 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