如何將單個或所有圖表從Excel工作表導(dǎo)出到PowerPoint?
有時,出于某些目的,您可能需要將圖表或所有圖表從Excel導(dǎo)出到PowerPoint。 本文討論的是如何實(shí)現(xiàn)它。
使用VBA代碼將單個圖表或所有圖表從Excel工作表導(dǎo)出到PowerPoint
使用VBA代碼將單個圖表或所有圖表從Excel工作表導(dǎo)出到PowerPoint
驚人的! 在 Excel 中使用高效的選項卡,如 Chrome、Firefox 和 Safari!
每天節(jié)省50%的時間,并減少數(shù)千次鼠標(biāo)單擊!
本節(jié)將介紹VBA代碼,以將單個圖表或所有圖表從工作簿導(dǎo)出到PowerPoint。 請執(zhí)行以下操作。
1。 按 其他 + F11 鑰匙一起打開 Microsoft Visual Basic應(yīng)用程序 窗口。
2.在 Microsoft Visual Basic應(yīng)用程序 窗口中,單擊 工具 > 參考資料 如下圖所示。
3.在 參考– VBAProject 對話框中,向下滾動以查找并檢查 Microsoft PowerPoint對象庫 選項,然后單擊 OK 按鈕。 看截圖:
4。 然后點(diǎn)擊 插頁 > 模塊.
5.如果要將單個圖表導(dǎo)出到PowerPoint,請轉(zhuǎn)到在工作表中選擇圖表,然后返回到 Microsoft Visual Basic應(yīng)用程序 窗口,將下面的VBA代碼復(fù)制并粘貼到“模塊”窗口中。
VBA代碼:將單個圖表從Excel工作表導(dǎo)出到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
如果要從工作簿中導(dǎo)出所有圖表,請復(fù)制以下VBA代碼并將其粘貼到“模塊”窗口中。
VBA代碼:將所有圖表從Excel工作表導(dǎo)出到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 鍵或單擊“運(yùn)行”按鈕以運(yùn)行代碼。 然后將打開一個新的PowerPoint,其中包含選定的圖表或所有導(dǎo)入的圖表。 你會得到一個 Kutools for Excel 對話框如下圖所示,請點(diǎn)擊 OK 按鈕。
相關(guān)文章:
如何在Excel中保存,導(dǎo)出多個/所有工作表到單獨(dú)的csv或文本文件?
如何在Excel中將所選內(nèi)容或整個工作簿另存為PDF?
最佳辦公生產(chǎn)力工具
將小時轉(zhuǎn)化為分鐘 Kutools for Excel!
準(zhǔn)備好增強(qiáng)您的 Excel 任務(wù)了嗎? 利用的力量 Kutools for Excel - 您終極的節(jié)省時間的工具。 簡化復(fù)雜的任務(wù)并像專業(yè)人士一樣瀏覽數(shù)據(jù)。 以閃電般的速度體驗(yàn) Excel!
為什么需要 Kutools for Excel
??? 超過 300 項強(qiáng)大功能: Kutools 包含 300 多項高級功能,可簡化您在 1500 多種場景中的工作。
?? 卓越的數(shù)據(jù)處理能力:合并單元格、刪除重復(fù)項并執(zhí)行高級數(shù)據(jù)轉(zhuǎn)換 - 所有這些都不費(fèi)吹灰之力!
?? 高效的批量操作:當(dāng)你可以聰明地工作時,為什么還要付出額外的努力呢? 輕松批量導(dǎo)入、導(dǎo)出、組合和調(diào)整數(shù)據(jù)。
?? 可定制的圖表和報告:訪問各種附加圖表并生成富有洞察力的報告。
??? 強(qiáng)大的導(dǎo)航窗格:通過強(qiáng)大的列管理器、工作表管理器和自定義收藏夾獲得優(yōu)勢。

?? 七種類型的下拉列表:通過各種功能和類型的下拉列表使數(shù)據(jù)輸入變得輕而易舉。
?? 用戶友好:對于初學(xué)者來說輕而易舉,對于專家來說是一個強(qiáng)大的工具。
立即下載,與 Excel 一起穿越時空!
閱讀更多
免費(fèi)下載... 采購...
Office Tab 為 Office 帶來選項卡式界面,讓您的工作更輕松
在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發(fā)布者,Access,Visio和Project。
在同一窗口的新選項卡中而不是在新窗口中打開并創(chuàng)建多個
文檔。
每天將您的工作效率提高50%,并減少數(shù)百次鼠標(biāo)單擊!