Come esportare uno o tutti i grafici da fogli di lavoro Excel a PowerPoint?
A volte, potrebbe essere necessario esportare un grafico o tutti i grafici da Excel a PowerPoint per qualche scopo. Questo articolo parla di come ottenerlo.
Esporta un singolo grafico o tutti i grafici dal foglio di lavoro Excel a PowerPoint con codice VBA
Esporta un singolo grafico o tutti i grafici dal foglio di lavoro Excel a PowerPoint con codice VBA
Questa sezione introdurrà i codici VBA per esportare un singolo grafico o tutti i grafici dalla cartella di lavoro a PowerPoint. Si prega di fare quanto segue.
1. premi il altro + F11 chiavi insieme per aprire il Microsoft Visual Basic, Applications Edition finestra.
2. Nel Microsoft Visual Basic, Applications Edition finestra, fare clic Strumenti > Riferimenti come mostrato nell'immagine sottostante.
3. Nel Riferimenti - VBAProject finestra di dialogo, scorrere verso il basso per trovare e selezionare il file Libreria di oggetti di Microsoft PowerPoint opzione, quindi fare clic su OK pulsante. Vedi screenshot:
4. Quindi fare clic inserire > Moduli.
5. Se si desidera esportare un singolo grafico in PowerPoint, selezionare il grafico nel foglio di lavoro, quindi tornare al file Microsoft Visual Basic, Applications Edition finestra, copia e incolla il codice VBA sottostante nella finestra del modulo.
Codice VBA: esporta un singolo grafico dal foglio di lavoro Excel a 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
Se desideri esportare tutti i grafici dalla cartella di lavoro, copia e incolla il codice VBA seguente nella finestra del modulo.
Codice VBA: esporta tutti i grafici dai fogli di lavoro Excel a 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. premi il F5 o fare clic sul pulsante Esegui per eseguire il codice. Quindi verrà aperto un nuovo PowerPoint con il grafico selezionato o tutti i grafici importati. E otterrai un file Kutools for Excel finestra di dialogo come mostrato nell'immagine sottostante, fare clic su OK pulsante.
Articoli correlati:
- Come salvare, esportare più / tutti i fogli in file CSV o di testo separati in Excel?
- Come salvare la selezione o l'intera cartella di lavoro come PDF in Excel?
I migliori strumenti per la produttività in ufficio
Potenzia le tue competenze di Excel con Kutools per Excel e sperimenta l'efficienza come mai prima d'ora. Kutools per Excel offre oltre 300 funzionalità avanzate per aumentare la produttività e risparmiare tempo. Fai clic qui per ottenere la funzionalità di cui hai più bisogno...
Office Tab porta l'interfaccia a schede in Office e semplifica notevolmente il tuo lavoro
- Abilita la modifica e la lettura a schede in Word, Excel, PowerPoint, Publisher, Access, Visio e Project.
- Apri e crea più documenti in nuove schede della stessa finestra, piuttosto che in nuove finestre.
- Aumenta la produttività del 50% e riduce ogni giorno centinaia di clic del mouse!