ไปยังเนื้อหาหลัก

วิธีใช้ปุ่มคำสั่งเพื่อบันทึกแผ่นงานที่ใช้งานเป็นไฟล์ PDF ใน Excel

ขณะทำงานใน Microsoft Excel คุณอาจประสบปัญหาในการบันทึกแผ่นงานที่ใช้งานอยู่เป็นไฟล์ PDF ในบทความนี้คุณสามารถเรียนรู้วิธีบันทึกแผ่นงานที่ใช้งานอยู่เป็นไฟล์ PDF ด้วยรหัส VBA ผ่านปุ่มคำสั่ง และถ้าคุณต้องการบันทึกช่วงหรือแต่ละแผ่นงานในสมุดงานที่ใช้งานเป็นไฟล์ PDF แต่ละแผ่นบทความนี้ยังช่วยคุณได้

ใช้ปุ่มคำสั่งเพื่อบันทึกแผ่นงานที่ใช้งานอยู่เป็นไฟล์ PDF ด้วยรหัส VBA
บันทึกที่ใช้งานอยู่หรือแต่ละแผ่นงานเป็นไฟล์ PDF แต่ละไฟล์ได้อย่างง่ายดายด้วย Kutools for Excel


ใช้ปุ่มคำสั่งเพื่อบันทึกแผ่นงานที่ใช้งานอยู่เป็นไฟล์ PDF ด้วยรหัส VBA

คุณสามารถเรียกใช้รหัส VBA ต่อไปนี้เพื่อบันทึกแผ่นงานที่ใช้งานอยู่เป็นไฟล์ PDF โดยคลิกที่ปุ่มคำสั่ง กรุณาดำเนินการดังนี้

1. ประการแรกคุณต้องสร้างโฟลเดอร์ชื่อ PDF เพื่อบันทึกไฟล์ PDF ที่แปลงใหม่ของคุณ ที่นี่ฉันสร้างโฟลเดอร์นี้ในดิสก์ในเครื่องของฉัน (C :)

2. กรุณาใส่ปุ่มคำสั่งโดยคลิก ผู้พัฒนา > สิ่งที่ใส่เข้าไป > ปุ่มคำสั่ง (ActiveX Control). ดูภาพหน้าจอ:

2. จากนั้นวาดปุ่มคำสั่งในแผ่นงานที่คุณต้องการเพิ่มแถวใหม่คลิกขวาที่ปุ่มคำสั่งแล้วคลิก อสังหาริมทรัพย์ จากเมนูคลิกขวา

3 ใน อสังหาริมทรัพย์ ให้ป้อนข้อความที่แสดงของปุ่มคำสั่งลงในไฟล์ คำบรรยายภาพ ภายใต้ หมวดหมู่ จากนั้นปิดกล่องโต้ตอบ

คุณสามารถเห็นข้อความที่แสดงของปุ่มคำสั่งเปลี่ยนไปตามภาพด้านล่างที่แสดง

4. คลิกขวาที่ปุ่มคำสั่งอีกครั้งจากนั้นคลิก ดูรหัส จากเมนูคลิกขวา

5. ในการเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน โปรดแทนที่รหัสเดิมในหน้าต่างรหัสด้วยรหัส VBA ต่อไปนี้

รหัส 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 พร้อมกันเพื่อปิดไฟล์ Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง. จากนั้นปิดไฟล์ โหมดการออกแบบ ภายใต้ ผู้พัฒนา แถบ

ตอนนี้คลิกที่ปุ่มคำสั่งแผ่นงานที่ใช้งานอยู่จะถูกบันทึกเป็นไฟล์ PDF ชื่อส่งออกและอยู่ในตำแหน่งที่ระบุ


บันทึกแต่ละแผ่นงานเป็นไฟล์ PDF ของสมุดงานที่ใช้งานอยู่ด้วย Kutools for Excel

ที่นี่แนะนำ แยกสมุดงาน ประโยชน์ของ Kutools สำหรับ Excel เพื่อบันทึกแผ่นงานที่ใช้งานอยู่เป็นไฟล์ PDF ได้อย่างง่ายดาย นอกจากนี้คุณยังสามารถบันทึกแต่ละแผ่นงานในสมุดงานปัจจุบันเป็นไฟล์ PDF แต่ละไฟล์ด้วยยูทิลิตี้นี้

ก่อนที่จะใช้ Kutools สำหรับ Excelโปรด ดาวน์โหลดและติดตั้งในตอนแรก.

1. ในสมุดงานคุณต้องบันทึกแผ่นงานแต่ละแผ่นเป็นไฟล์ PDF แต่ละแผ่นจากนั้นคลิก Kutools พลัส > สมุดงาน > แยกสมุดงาน. ดูภาพหน้าจอ:

2 ใน แยกสมุดงาน โปรดกำหนดค่าดังต่อไปนี้:

2.1) ตรวจสอบเฉพาะชื่อแผ่นงานที่ใช้งานอยู่ในไฟล์ ชื่อแผ่นงาน กล่อง;
2.2) เลือก PDF (* .pdf) ตัวเลือกจาก บันทึกเป็นชนิด รายการแบบหล่นลง
2.3) คลิกปุ่ม แยก แล้วปุ่ม เลือกโฟลเดอร์ กล่องโต้ตอบปรากฏขึ้นระบุโฟลเดอร์ที่จะบันทึกไฟล์ PDF

จากนั้นแผ่นงานที่เลือกจะถูกบันทึกเป็นไฟล์ PDF ทันที

หมายเหตุ / รายละเอียดเพิ่มเติม:

1. คุณสามารถตรวจสอบชื่อแผ่นงานหลายชื่อในกล่องชื่อแผ่นงานเพื่อบันทึกเป็นไฟล์ pdf แต่ละไฟล์พร้อมกัน
2. ยกเว้นการบันทึกแผ่นงานเป็นไฟล์ pdf คุณสามารถบันทึกแผ่นงานเป็น txt ได้ หรือ csv. ไฟล์ตามที่คุณต้องการ

  หากคุณต้องการทดลองใช้ยูทิลิตีนี้ฟรี (30 วัน) กรุณาคลิกเพื่อดาวน์โหลดแล้วไปใช้การดำเนินการตามขั้นตอนข้างต้น


Demo: บันทึกการเลือกหรือแต่ละแผ่นงานเป็น PDF ด้วย Kutools for Excel


บทความที่เกี่ยวข้อง:

สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน

🤖 Kutools AI ผู้ช่วย: ปฏิวัติการวิเคราะห์ข้อมูลโดยยึดตาม: การดำเนินการที่ชาญฉลาด   |  สร้างรหัส  |  สร้างสูตรที่กำหนดเอง  |  วิเคราะห์ข้อมูลและสร้างแผนภูมิ  |  เรียกใช้ฟังก์ชัน Kutools...
คุณสมบัติยอดนิยม: ค้นหา เน้น หรือระบุรายการที่ซ้ำกัน   |  ลบแถวว่าง   |  รวมคอลัมน์หรือเซลล์โดยไม่สูญเสียข้อมูล   |   รอบโดยไม่มีสูตร ...
การค้นหาขั้นสูง: VLookup หลายเกณฑ์    VLookup หลายค่า  |   VLookup ข้ามหลายแผ่น   |   การค้นหาที่ไม่ชัดเจน ....
รายการแบบเลื่อนลงขั้นสูง: สร้างรายการแบบหล่นลงอย่างรวดเร็ว   |  รายการแบบหล่นลงขึ้นอยู่กับ   |  เลือกหลายรายการแบบหล่นลง ....
ผู้จัดการคอลัมน์: เพิ่มจำนวนคอลัมน์เฉพาะ  |  ย้ายคอลัมน์  |  สลับสถานะการมองเห็นของคอลัมน์ที่ซ่อนอยู่  |  เปรียบเทียบช่วงและคอลัมน์ ...
คุณสมบัติเด่น: กริดโฟกัส   |  มุมมองการออกแบบ   |   บาร์สูตรใหญ่    สมุดงานและตัวจัดการชีต   |  ห้องสมุดทรัพยากร (ข้อความอัตโนมัติ)   |  เลือกวันที่   |  รวมแผ่นงาน   |  เข้ารหัส/ถอดรหัสเซลล์    ส่งอีเมลตามรายการ   |  ซุปเปอร์ฟิลเตอร์   |   ตัวกรองพิเศษ (กรองตัวหนา/ตัวเอียง/ขีดทับ...) ...
ชุดเครื่องมือ 15 อันดับแรก12 ข้อความ เครื่องมือ (เพิ่มข้อความ, ลบอักขระ, ... )   |   50 + แผนภูมิ ประเภท (แผนภูมิ Gantt, ... )   |   40+ ใช้งานได้จริง สูตร (คำนวณอายุตามวันเกิด, ... )   |   19 การแทรก เครื่องมือ (ใส่ QR Code, แทรกรูปภาพจากเส้นทาง, ... )   |   12 การแปลง เครื่องมือ (ตัวเลขเป็นคำ, การแปลงสกุลเงิน, ... )   |   7 ผสานและแยก เครื่องมือ (แถวรวมขั้นสูง, แยกเซลล์, ... )   |   ... และอื่น ๆ

เพิ่มพูนทักษะ Excel ของคุณด้วย Kutools สำหรับ Excel และสัมผัสประสิทธิภาพอย่างที่ไม่เคยมีมาก่อน Kutools สำหรับ Excel เสนอคุณสมบัติขั้นสูงมากกว่า 300 รายการเพื่อเพิ่มประสิทธิภาพและประหยัดเวลา  คลิกที่นี่เพื่อรับคุณสมบัติที่คุณต้องการมากที่สุด...

รายละเอียด


แท็บ Office นำอินเทอร์เฟซแบบแท็บมาที่ Office และทำให้งานของคุณง่ายขึ้นมาก

  • เปิดใช้งานการแก้ไขและอ่านแบบแท็บใน Word, Excel, PowerPoint, ผู้จัดพิมพ์, Access, 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