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

كيفية تعطيل أو عدم السماح بخيارات حفظ وحفظ باسم في إكسيل؟

عادةً ، عند النقر فوق حفظ أو حفظ باسم ، سيتم حفظ بياناتنا المعدلة في المصنف مرة واحدة. لكن ، في بعض الأحيان ، لا يسمح للمستخدمين الآخرين بتعديل ملف Excel وحفظه عند قراءة الملف. توفر هذه المقالة طريقة VBA لتعطيل خيارات Save & Save As في Excel.

قم بتعطيل خيارات Save & Save As باستخدام كود VBA


قم بتعطيل خيارات Save & Save As باستخدام كود VBA

يمكنك تشغيل رمز VBA أدناه لتعطيل خيارات Save & Save As في Excel.

1. في المصنف ، تحتاج إلى تعطيل وظائف Save & Save As ، يرجى الضغط على قديم + F11 مفاتيح في نفس الوقت لفتح ميكروسوفت فيسوال باسيك للتطبيقات نافذة.

2. في ال ميكروسوفت فيسوال باسيك للتطبيقات نافذة ، انقر مرتين ThisWorkbook في الشريط الأيسر ، انسخ والصق VBA 1 أدناه في نافذة Code ، ثم انقر فوق حفظ زر. انظر لقطة الشاشة:

VBA 1: قم بتعطيل خيارات Save & Save As في Excel

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    ThisWorkbook.Saved = True
End Sub

3. في الافتتاح حفظ باسم ، حدد مجلدًا لحفظ المصنف ، وقم بتسمية المصنف كما تريد وحدد مصنف Excel ممكن بماكرو من حفظ كنوع القائمة المنسدلة ، ثم انقر فوق الزر حفظ .

4. الآن انسخ والصق VBA 2 أدناه في ملف ThisWorkbook نافذة التعليمات البرمجية. انظر لقطة الشاشة.

VBA 2: قم بتعطيل خيارات Save & Save As في Excel

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim xName As String
xName = "CancelBeforeSave"

If Not Evaluate("=ISREF('" & xName & "'!A1)") Then
    Sheets.Add(after:=Worksheets(Worksheets.count)).Name = xName & ""
    Sheets(xName & "").Move after:=Worksheets(Worksheets.count)
    Sheets(xName & "").Visible = False
    Exit Sub
End If
    Cancel = True
End Sub

5. انقر فوق حفظ زر لحفظ الرمز ، ثم أغلق المصنف.

تم حفظ المصنف كمصنف Excel Macro-Enabled مع ملحق حفظ و حفظ باسم وظائف معطلة.

ملاحظات: يبدو أنه يتم حفظ التغييرات في ورقة العمل الحالية في كل مرة تقوم فيها بتعديل المصنف وحفظه. ولكن بعد إغلاق المصنف وإعادة فتحه ، ستجد أنه تم فشل حفظ التغييرات.

أفضل أدوات إنتاجية المكتب

🤖 مساعد 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 (28)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
When I try to save this in the code window, it shows an error message about Add, in the line:
Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = xName & ""

how do I fix?
This comment was minimized by the moderator on the site
It is possible that user receiving the file will disable the macros and controlwill not work. Please help understand.
This comment was minimized by the moderator on the site
Hi Deepak Kachare,
If you don't want others users disable the macros after they receiving the file, you can hide the macro code that no one can open and see it.
See if the method in the following article can help you.
How to Protect and Hide Excel Macros
This comment was minimized by the moderator on the site
Thanks for your response. I think the link is an erroneous one. Could you please help with the link.
This comment was minimized by the moderator on the site
Hi DEEPAK KACHARE,
Sorry for the mistake. To protect and hide Excel macros, you need to configure as follows.
1. Click the Alt + F11 keys to open the VBA editor.
2. In the editor, click Tools > VBAProject Properties.
https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/vba3.png
3. In the VBAProject Properties dialog box, go to the Protection tab, check the Lock project for viewing box, enter password and finally click OK.
https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/vba4.png
From now on, anyone (including yourself) who wants to open the VBA editor of this workbook, a password is required.
This comment was minimized by the moderator on the site
I've just discovered that as soon as I place a shortcut to this file in another location (where the others are going to access it) all my protections no longer work. The sheet is not protected (which I have previously set), the workbook is not protected (which I have also previously set) and the Save-Save As ability is now there, as if the VBA code were not there at all. If I go to the original file, it all still works.

What is it about the shortcut that is stripping all the protections away?
This comment was minimized by the moderator on the site
Hi Rochelley,
The VBA code cannot figure out which way the workbook is opened. So it can't stop others from changing the file by opening it through a shortcut.
Sorry I can't help to with this problem.
For the first issue you mentioned above, I need time to see if I can handle it.
This comment was minimized by the moderator on the site
Hi, Thanks very much, this is exactly what I need, to prevent others from saving or saving as a file in any location, and it is working for me, thanks to the comment about "Design Mode".

However, I still need to be able to make edits to the file periodically and save the changes. Must I delete the VBA code first, make the changes, Save, and then add the VBA code back in again to prevent others from saving? Or is there a simpler way to make edits and save while leaving the VBA code intact?
This comment was minimized by the moderator on the site
Hi Rochelley,
Thank you for your feedback. The VBA code has been updated as follow. You need to:
1. Press the Alt + F11 keys to open the Visual Basic editor.
2. In the Visual Basic editor, double click ThisWorkbook in the left Project pane, and then copy the following VBA code into ThisWorkbook (Code) window.
3. Save the code and save the workbook as an Excel Macro-Enabled Workbook.
Notes:
1) In the code, "Win10x64Test" stands for the username in your operating system. Please change it to your own username.
2) After adding the code, you can edit the workbook and save it as usual. But if someone else gets this workbook, the Save and Save as options will not be avaliable.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Updated by Extendoffice 20220930
    ThisWorkbook.Saved = True
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim xName As String
xName = "Win10x64Test" 'The username in your operating system

If xName <> Environ("username") Then
Cancel = True
End If
End Sub
This comment was minimized by the moderator on the site
For all of those who encountered the error where after already doing this once, when they try do it again the code won't save:

Go to the bottom of the excel file where it shows the sheets
Right-click the sheets
Press Unhide
Delete the sheet called CancelBeforeSave
This comment was minimized by the moderator on the site
Brilliant !   
This comment was minimized by the moderator on the site
Thanks for your reply. Highly appreciated. I want you to guide me how to send a saved file to a friend who can open my file but only read or edit it, but can not not save the file in any folder.
1. For instance I have a saved file, which I want to send to "A" He opens the saved file but after opening he reads or makes any changes in my file, he can not save it at his end in any folder.
2. I have got code form internet which disallows to save. But in this case when I copy and paste the code, the file does not save. So I can not send the file to him
3. How can I send the file to Party "A" with a saved code in the hope he can not save the file.
This comment was minimized by the moderator on the site
I tried to use the code for NOT SAVING the file. But it did not work. It saves the file.
This comment was minimized by the moderator on the site
Please, I do not want someone to copy or save my excel file, how can I remove save or save as?
This comment was minimized by the moderator on the site
Hello I am a fan of this website...I used to try the code. It works flawlessly. But it disables "Save option" too. I am not able to save the Excel sheet. What I need is to disable only the feature "Save As" I read the other user's comments too. ThisWorkbookSaved = True is not working for me as well. Could you please help? Thanks a lot for all your contributions.
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