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

كيفية استخدام زر الأمر لحفظ ورقة العمل النشطة كملف PDF في Excel؟

أثناء العمل في Microsoft Excel ، قد تواجه مشكلة حفظ ورقة العمل النشطة كملف PDF. في هذه المقالة ، يمكنك التعرف على كيفية حفظ ورقة العمل النشطة كملف PDF برمز VBA من خلال زر الأمر. وإذا كنت تريد أيضًا حفظ نطاق أو كل ورقة عمل في مصنف نشط كملف PDF فردي ، فيمكن أن تساعدك هذه المقالة أيضًا.

استخدم زر الأمر لحفظ ورقة العمل النشطة كملف PDF برمز VBA
احفظ بسهولة أو كل ورقة عمل كملف PDF فردي باستخدام Kutools for Excel


استخدم زر الأمر لحفظ ورقة العمل النشطة كملف PDF برمز VBA

يمكنك تشغيل كود فبا التالي لحفظ ورقة عمل نشطة كملف PDF من خلال النقر على زر الأمر. الرجاء القيام بما يلي.

1. أولاً ، تحتاج إلى إنشاء مجلد باسم PDF لحفظ ملف PDF المحول الجديد. هنا أقوم بإنشاء هذا المجلد في القرص المحلي الخاص بي (C :).

2. الرجاء إدخال زر الأمر بالنقر فوق المطور > إدراج > زر الأمر (عنصر تحكم ActiveX). انظر لقطة الشاشة:

2. ثم ارسم زر الأمر إلى ورقة العمل التي تريد إضافة صفوف جديدة إليها ، انقر بزر الماوس الأيمن فوق زر الأمر وانقر عقارات من قائمة النقر بزر الماوس الأيمن.

3. في ال عقارات في مربع الحوار ، أدخل النص المعروض لزر الأمر في ملف شرح مربع تحت مصنف علامة التبويب ، ثم أغلق مربع الحوار.

يمكنك أن ترى تغيير النص المعروض لزر الأمر كما هو موضح أدناه لقطة الشاشة.

4. انقر بزر الماوس الأيمن فوق زر الأمر مرة أخرى ، ثم انقر فوق عرض الرمز من قائمة النقر بزر الماوس الأيمن.

5. في الافتتاح ميكروسوفت فيسوال باسيك للتطبيقات النافذة ، يرجى استبدال الكود الأصلي في نافذة التعليمات البرمجية برمز VBA التالي.

كود فبا: زر الأمر لحفظ ورقة العمل النشطة بصيغة PDF

Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:="C:\PDF\Export.pdf", _
            OpenAfterPublish:=False
    Application.ScreenUpdating = True
End Sub

ملاحظات: في الكود ، CommandButton1 هو اسم زر الأمر الذي ستستخدمه لحفظ الورقة النشطة كملف PDF. "C: \ PDF \ Export.pdf" هو مسار واسم ملف PDF الذي يتم حفظه.

6. اضغط على قديم + Q مفاتيح في نفس الوقت لإغلاق ميكروسوفت فيسوال باسيك للتطبيقات نافذة او شباك. ثم قم بإيقاف تشغيل وضع التصميم تحت المطور علامة التبويب.

الآن ، انقر فوق زر الأمر ، سيتم حفظ ورقة العمل النشطة كملف PDF باسم تصدير وتقع في الموقع المحدد.


احفظ كل ورقة عمل كملف PDF فردي من مصنف نشط باستخدام Kutools for Excel

هنا نوصي انقسام وركبوك فائدة كوتولس ل إكسيل لحفظ ورقة العمل النشطة بسهولة كملف PDF. بالإضافة إلى ذلك ، يمكنك أيضًا حفظ كل ورقة عمل في المصنف الحالي كملف PDF فردي باستخدام هذه الأداة.

قبل التطبيق كوتولس ل إكسيلالرجاء قم بتنزيله وتثبيته أولاً.

1. في المصنف ، تحتاج إلى حفظ كل ورقة عمل كملف PDF فردي ، ثم انقر فوق كوتولس بلس > مصنف > انقسام وركبوك. انظر لقطة الشاشة:

2. في ال انقسام وركبوك مربع الحوار ، يرجى التهيئة على النحو التالي:

2.1) تحقق فقط من اسم الورقة النشط في ملف اسم ورقة العمل صندوق؛
شنومكس) حدد PDF (* .pdf) الخيار من حفظ كنوع قائمة منسدلة؛
شنومكس) انقر فوق الانقسام زر ، ثم أ حدد المجلد ينبثق مربع الحوار ، حدد مجلدًا لحفظ ملف PDF ؛

ثم يتم حفظ ورقة العمل المحددة كملف PDF على الفور.

ملاحظة:

1. يمكنك التحقق من أسماء أوراق عمل متعددة في مربع اسم ورقة العمل لحفظها كملف pdf فردي مرة واحدة ؛
2. باستثناء حفظ ورقة العمل كملفات pdf ، يمكنك حفظ أوراق العمل بتنسيق txt. أو csv. ملف ما تحتاجه.

  إذا كنت ترغب في الحصول على نسخة تجريبية مجانية (30 يومًا) من هذه الأداة المساعدة ، الرجاء الضغط لتنزيلهثم انتقل لتطبيق العملية حسب الخطوات المذكورة أعلاه.


العرض التوضيحي: احفظ التحديد أو كل ورقة عمل بتنسيق PDF باستخدام Kutools for Excel


مقالات ذات صلة:

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

🤖 مساعد 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 (33)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Ich nutze diese Zeilen und das funktioniert auch gut, mein Problem ist nur, sollte diese Datei bereits vorhanden sein, WIRD diese einfach überschrieben!
Wie kann ich das vermeiden, es sollte eine Meldung kommen, Datei existiert bereits und es soll beendet werden?


Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="X:\firmen\Buchhaltung\Rechnungs-Kopie_Ackermann Service GmbH\2022\RK-Abrechnung\" & ActiveSheet.Range("G1") & ".pdf", _
OpenAfterPublish:=True
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hi Sascha,
The following VBA code can help. Please give it a try.

Private Sub CommandButton1_Click()
'Updated by Extendoffice 20221230
    Dim xPDFName As String
    Dim xPDFPath As String
    Dim xObjFS As Object
    Dim xNum As Integer
    Dim xStr As String
    
    xPDFName = "Export" 'The file name
    xPDFPath = "D:\work\Jan\test\" 'The file path
    Application.ScreenUpdating = True
    On Error Resume Next
    Set xObjFS = CreateObject("Scripting.FileSystemObject")
    xStr = xPDFPath & xPDFName & ".pdf"
    xNum = 1
    If xObjFS.FileExists(xStr) Then
    xResponse = MsgBox("The file already exists, do you want to overwrite it?", vbYesNo, "www.extendoffice.com", "", 0)
       If xResponse <> vbYes Then
       Exit Sub
      End If
    End If
    Application.ScreenUpdating = False
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
            FileName:=xStr, _
            OpenAfterPublish:=False
    Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Ich nutze diese Zeilen und das funktioniert auch gut, mein Problem ist nur, sollte diese Datei bereits vorhanden sein, wird diese einfach überschrieben!
Wie kann ich das vermeiden, es sollte eine Meldung kommen, Datei existiert bereits und es soll beendet werden?
This comment was minimized by the moderator on the site
When I run the below it creates a local version of the PDF automatically - how do I stop this from automatically saving?

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
OpenAfterPublish:=True
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hi James,
Do you want to pop up a window to select a folder to save the PDF file manually?
This comment was minimized by the moderator on the site
Hi Crystal, ideally yes so I can then choose where to save the PDF.
This comment was minimized by the moderator on the site
H James,

The following VBA code can help you solve the problem.
Note: You can't handle both the destination and the file name at the same time. After adding the following VBA code, when you click the button, a dialog box will pop up for you to select a destination folder. After selecting a destination folder, a box will pop up for you to give a name to the PDF file.

Private Sub CommandButton1_Click()
'Updated by Extendoffice 20221223
    Dim xDlg As FileDialog
    Dim xFolder As Variant
    Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
    Dim xStrName As String
    If xDlg.Show <> -1 Then Exit Sub
    
    xFolder = xDlg.SelectedItems(1)
    
    xStart = InputBox("file name", "KuTools for Excel", ActiveSheet.Name & ".pdf")

    Application.ScreenUpdating = False

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:=xFolder & "\" & xStart, _
            OpenAfterPublish:=False
    Application.ScreenUpdating = True

End Sub
This comment was minimized by the moderator on the site
Whenever I run this it saves a PDF to my local drive where the excel sheets saved, how do I stop this from auto saving?

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
OpenAfterPublish:=True
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hi Team,

Just wondering if anyone could help with changing the destination of the created file to any user's desktop? My compnay doesn't allow access to C: so the script doesn't work.

MANY MANY MANY thanks!
This comment was minimized by the moderator on the site
Hi Ben Stoddart,
You just need to open any folder on your desktop and copy the folder path in the address box, then replace the folder path in the VBA code with the path you copied.
Here is the new Filename line (please replace the Username with your own username), Export.pdf is the name and the file extension of the PDF file:
Filename:="C:\Users\Username\Desktop\PDF\Export.pdf", _
This comment was minimized by the moderator on the site
Goededag

is het mogelijk om een filmpje of een voorbeeld excelblad te maken voor de Command-Knop Om Een ​​Actief Werkblad Op Te Slaan Als PDF-Bestand Met VBA-Code.
kom er niet helemaal uit met de codes.
alvast bedankt
This comment was minimized by the moderator on the site
Hi max,
Sorry I don't understand what you mean. You may need to attach a screenshot of what you are trying to do. Sorry for the inconvenience.
This comment was minimized by the moderator on the site
Что это за кнопка - "другой" + Q клавиши одновременно" ? Не поняла что нажимать, подскажите, пожалуйста
This comment was minimized by the moderator on the site
Hi Диана,
It is the "Alt" key on your keyboard. Microsoft Excel allows users to press the "Alt" + "Q" keys to close the Microsoft Visual Basic for Applications window and return to the worksheet.
This comment was minimized by the moderator on the site
Hallo,

ich nutze diese Zeilen und möchte das eine Zelle als Dateiname verwenden wird!
Kann mir jemand ein Tipp geben?


Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="c:/" & G3 & ".pdf", _
OpenAfterPublish:=False
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hi Sascha,
The following code can help. Before applying the code, please change 'C:\Users\Win10x64Test\Documents\PDF' in the fourth line to you own destination folder path.
Private Sub CommandButton1_Click()
'Updated by Extendoffice 20220929
    Application.ScreenUpdating = False
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:="C:\Users\Win10x64Test\Documents\PDF\" & Range("G3").Value, _
            OpenAfterPublish:=False
    Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hallo,

kann jemand mir helfen?

Ich nutze diese Zeilen und möchte jedoch, das aus dem Blatt ein Zellenwert als Dateiname gespeichert wird:

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\PDF\Export.pdf", _
OpenAfterPublish:=False
Application.ScreenUpdating = True
End Sub

Danke
This comment was minimized by the moderator on the site
ive followed the code, this is what i have:

Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=Range("P2"), _
OpenAfterPublish:=True
Application.ScreenUpdating = True
End Sub

i need the file to save to the location that the orignal file is located. also need a copy of the excel file to save aswell with the same name.
This comment was minimized by the moderator on the site
Hi Matt Bentley,
The code works perfectly. Thank you for sharing.
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