วิธีการส่งออกแผนภูมิเดียวหรือทั้งหมดจากแผ่นงาน Excel ไปยัง PowerPoint
บางครั้งคุณอาจต้องส่งออกแผนภูมิหรือแผนภูมิทั้งหมดจาก Excel ไปยัง PowerPoint เพื่อจุดประสงค์บางอย่าง บทความนี้กำลังพูดถึงวิธีการบรรลุ
ส่งออกแผนภูมิเดียวหรือแผนภูมิทั้งหมดจากแผ่นงาน Excel ไปยัง PowerPoint ด้วยรหัส VBA
ส่งออกแผนภูมิเดียวหรือแผนภูมิทั้งหมดจากแผ่นงาน Excel ไปยัง PowerPoint ด้วยรหัส VBA
ส่วนนี้จะแนะนำรหัส VBA เพื่อส่งออกแผนภูมิเดียวหรือแผนภูมิทั้งหมดจากสมุดงานไปยัง PowerPoint กรุณาดำเนินการดังนี้
1 กด อื่น ๆ + F11 คีย์ร่วมกันเพื่อเปิดไฟล์ Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง
2 ใน Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่างคลิก เครื่องมือ > อ้างอิง ดังภาพด้านล่างที่แสดง
3 ใน เอกสารอ้างอิง - VBAProject กล่องโต้ตอบเลื่อนลงเพื่อค้นหาและตรวจสอบไฟล์ ไลบรารีวัตถุ Microsoft PowerPoint จากนั้นคลิกตัวเลือก OK ปุ่ม. ดูภาพหน้าจอ:
4 จากนั้นคลิก สิ่งที่ใส่เข้าไป > โมดูล.
5. หากคุณต้องการส่งออกแผนภูมิเดียวไปยัง PowerPoint โปรดไปที่เลือกแผนภูมิในแผ่นงานจากนั้นกลับไปที่ไฟล์ Microsoft Visual Basic สำหรับแอปพลิเคชัน คัดลอกและวางโค้ด VBA ด้านล่างลงในหน้าต่างโมดูล
รหัส VBA: ส่งออกแผนภูมิเดียวจากแผ่นงาน Excel ไปยัง PowerPoint
Sub SingleActiveChartToPowerPoint_EarlyBinding1()
'Updated by Extendoffice 2017/9/15
Dim pptApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim pptSlide As PowerPoint.Slide
Dim pptShape As PowerPoint.Shape
Dim pptShpRng As PowerPoint.ShapeRange
Dim xActiveSlideNow As Long
On Error Resume Next
If ActiveChart Is Nothing Then
MsgBox "Select a chart and try again!", vbExclamation, "KuTools For Excel"
Exit Sub
End If
Set pptApp = GetObject(, "PowerPoint.Application")
If pptApp Is Nothing Then
Set pptApp = CreateObject("PowerPoint.Application")
Set pptPres = pptApp.Presentations.Add
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
Else
If pptApp.Presentations.Count > 0 Then
Set pptPres = pptApp.ActivePresentation
If pptPres.Slides.Count > 0 Then
xActiveSlideNow = pptApp.ActiveWindow.View.Slide.SlideIndex
Set pptSlide = pptPres.Slides(xActiveSlideNow)
Else
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
End If
Else
Set pptPres = pptApp.Presentations.Add
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
End If
End If
ActiveChart.ChartArea.Copy
With pptSlide
.Shapes.Paste
Set pptShape = .Shapes(.Shapes.Count)
Set pptShpRng = .Shapes.Range(pptShape.Name)
End With
With pptShpRng
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
End With
pptShpRng.Select
End Sub
หากคุณต้องการส่งออกแผนภูมิทั้งหมดจากสมุดงานโปรดคัดลอกและวางโค้ด VBA ด้านล่างลงในหน้าต่างโมดูล
รหัส VBA: ส่งออกแผนภูมิทั้งหมดจากแผ่นงาน Excel ไปยัง PowerPoint
Option Explicit
'Updated by Extendoffice 2017/9/15
Dim pptApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim pptSlide As PowerPoint.Slide
Dim pptSlideCount As Integer
Sub ChartsToPowerPoint()
Dim xSheet As Worksheet
Dim xChartsCount As Integer
Dim xChart As Object
Dim xActiveSlideNow As Integer
On Error Resume Next
For Each xSheet In ActiveWorkbook.Worksheets
xChartsCount = xChartsCount + xSheet.ChartObjects.Count
Next xSheet
If xChartsCount = 0 Then
MsgBox "Sorry, there are no charts to export!", vbCritical, "Ops"
Exit Sub
End If
Set pptApp = GetObject(, "PowerPoint.Application")
If pptApp Is Nothing Then
Set pptApp = CreateObject("PowerPoint.Application")
Set pptPres = pptApp.Presentations.Add
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
Else
If pptApp.Presentations.Count > 0 Then
Set pptPres = pptApp.ActivePresentation
If pptPres.Slides.Count > 0 Then
xActiveSlideNow = pptApp.ActiveWindow.View.Slide.SlideIndex
Set pptSlide = pptPres.Slides(xActiveSlideNow)
Else
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
End If
Else
Set pptPres = pptApp.Presentations.Add
Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
End If
End If
For Each xSheet In ActiveWorkbook.Worksheets
For Each xChart In xSheet.ChartObjects
Call pptFormat(xChart.Chart)
Next xChart
Next xSheet
For Each xChart In ActiveWorkbook.Charts
Call pptFormat(xChart)
Next xChart
Set pptSlide = Nothing
Set pptPres = Nothing
Set pptApp = Nothing
MsgBox "The charts were copied successfully to the new presentation!", vbInformation, "KuTools For Excel"
End Sub
Private Sub pptFormat(xChart As Chart)
Dim xCharTiTle As String
Dim I As Integer
On Error Resume Next
xCharTiTle = xChart.ChartTitle.Text
xChart.ChartArea.Copy
pptSlideCount = pptPres.Slides.Count
Set pptSlide = pptPres.Slides.Add(pptSlideCount + 1, ppLayoutBlank)
pptSlide.Select
pptSlide.Shapes.PasteSpecial ppPasteJPG
If xCharTiTle <> "" Then
pptSlide.Shapes.AddTextbox msoTextOrientationHorizontal, 12.5, 20, 694.75, 55.25
End If
For I = 1 To pptSlide.Shapes.Count
With pptSlide.Shapes(I)
Select Case .Type
Case msoPicture:
.Top = 87.84976
.left = 33.98417
.Height = 422.7964
.Width = 646.5262
Case msoTextBox:
With .TextFrame.TextRange
.ParagraphFormat.Alignment = ppAlignCenter
.Text = xCharTiTle
.Font.Name = "Tahoma (Headings)"
.Font.Size = 28
.Font.Bold = msoTrue
End With
End Select
End With
Next I
End Sub
6 กด F5 หรือคลิกปุ่ม Run เพื่อเรียกใช้รหัส จากนั้น PowerPoint ใหม่จะเปิดขึ้นพร้อมกับแผนภูมิที่เลือกหรือแผนภูมิทั้งหมดที่นำเข้า และคุณจะได้รับ Kutools สำหรับ Excel กล่องโต้ตอบด้านล่างภาพหน้าจอที่แสดงโปรดคลิกที่ไฟล์ OK ปุ่ม
บทความที่เกี่ยวข้อง:
- วิธีบันทึกส่งออกหลายแผ่น / ทั้งหมดเพื่อแยกไฟล์ csv หรือไฟล์ข้อความใน Excel
- วิธีบันทึกการเลือกหรือสมุดงานทั้งหมดเป็น PDF ใน Excel
สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน
เพิ่มพูนทักษะ Excel ของคุณด้วย Kutools สำหรับ Excel และสัมผัสประสิทธิภาพอย่างที่ไม่เคยมีมาก่อน Kutools สำหรับ Excel เสนอคุณสมบัติขั้นสูงมากกว่า 300 รายการเพื่อเพิ่มประสิทธิภาพและประหยัดเวลา คลิกที่นี่เพื่อรับคุณสมบัติที่คุณต้องการมากที่สุด...
แท็บ Office นำอินเทอร์เฟซแบบแท็บมาที่ Office และทำให้งานของคุณง่ายขึ้นมาก
- เปิดใช้งานการแก้ไขและอ่านแบบแท็บใน Word, Excel, PowerPoint, ผู้จัดพิมพ์, Access, Visio และโครงการ
- เปิดและสร้างเอกสารหลายรายการในแท็บใหม่ของหน้าต่างเดียวกันแทนที่จะเป็นในหน้าต่างใหม่
- เพิ่มประสิทธิภาพการทำงานของคุณ 50% และลดการคลิกเมาส์หลายร้อยครั้งให้คุณทุกวัน!