我有一個帶有幾個圖表和附加儀表板(如圖所示)的Excel文件。將Excel表格與指標複製到PowerPoint中的推薦方式
我複製從Excel圖表對象到PowerPoint,但不知道什麼是複製的附加儀表盤到PowerPoint的最佳途徑,因爲它包括一系列的Excel單元格中,一些指標使用條件格式化和一個圓形對象。
我不想將它複製爲圖片,因爲它看起來像在PowerPoint中失焦。
我已經添加了一段代碼(不是整件事情,因爲它很長),只是想知道複製這個儀表板圖像的方法。
Public Sub UpdatePowerPoint(PowerPointFile)
'Add a reference to the Microsoft PowerPoint Library by:
'1. Go to Tools in the VBA menu
'2. Click on Reference
'3. Scroll down to Microsoft PowerPoint X.0 Object Library, check the box, and press Okay
Dim ppProgram As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim ppFullPath As String
Dim ppName As String
Dim activeSlide As PowerPoint.Slide
Dim cht As Excel.ChartObject
Dim cht_count As Integer
Dim myShape As Object
Dim myChart As Object
Dim SlideNum, GPLRank As Integer
Dim ProjectIPPNum, ProjectName As String
Dim ShapeNum As Integer
Dim ExpenseActual, ExpenseBalance As Long
Dim StageStat As String
Dim nextKD As String
Dim shapeStageStat As Shape
On Error Resume Next
Set ppProgram = GetObject(, "PowerPoint.Application")
On Error GoTo 0
ppFullPath = PowerPointFile
If ppProgram Is Nothing Then
Set ppProgram = New PowerPoint.Application
i = 1
Else
If ppProgram.Presentations.Count > 0 Then
ppName = Mid(ppFullPath, InStrRev(ppFullPath, "\") + 1, Len(ppFullPath))
i = 1
ppCount = ppProgram.Presentations.Count
Do Until i = ppCount + 1
If ppProgram.Presentations.Item(i).Name = ppName Then
Set ppPres = ppProgram.Presentations.Item(i)
GoTo OnePager_Pres_Found
Else
i = i + 1
End If
Loop
End If
End If
ppProgram.Presentations.Open Filename:=PowerPointFile ' 'PowerPointFile = "C:\Test.pptx"
Set ppPres = ppProgram.Presentations.Item(i)
OnePager_Pres_Found:
ppPres.Windows(1).Activate ' activate the One-Pager Presentation in case you have several open, and the One_pager is currently not the app "on-focus"
' loop through all PowerPoint Slides, and copy all Chart objects from Excel
For ProjectCounter = 0 To NumberofProjectShts
Worksheets(ProjectShtName(ProjectCounter)).Activate
GPLRank = ActiveSheet.Cells(12, 2)
SlideNum = ActiveSheet.Cells(24, 2)
ProjectIPPNum = ActiveSheet.Cells(2, 2)
ProjectName = ActiveSheet.Cells(3, 2)
StageStat = ActiveSheet.Cells(20, 2)
nextKD = ActiveSheet.Cells(18, 2)
ExpenseActual = ActiveSheet.Cells(33, 4)
ExpenseBalance = ActiveSheet.Cells(33, 5)
On Error GoTo Error_PPTSlideNum_Handler
ppProgram.ActivePresentation.Slides(SlideNum).Select
Set myShape = ppProgram.ActivePresentation.Slides(SlideNum).Shapes
' --- loop throughout the Slide shapes and search for the Shape of type chart, then delete the old ones
For i = myShape.Count To 1 Step -1
If myShape.Item(i).HasChart Or myShape.Item(i).Type = msoEmbeddedOLEObject Or myShape.Item(i).Type = msoPicture Then
myShape.Item(i).Delete
Else
If myShape.Item(i).Left > 600 Then
myShape.Item(i).Delete
Else
Select Case myShape.Item(i).AutoShapeType
Case msoShapeOval, msoShapeOctagon, msoShapeIsoscelesTriangle
myShape.Item(i).Delete
End Select
End If
End If
Next
'Show the PowerPoint
ppProgram.Visible = True
' select the 1-Pager Slide number which we will update the charts with the Excel Charts
Set activeSlide = ppProgram.ActivePresentation.Slides(SlideNum)
' --- copy the dasboard (with Stage Status indicator) from Excel to Powerpoint , as Embedded Excel object ---
' this is the part I've added to copy the dashboard from Excel to PowerPoint slide
Columns("F:G").ColumnWidth = 7.71
Columns("H:J").ColumnWidth = 4.71
Rows("1:4").RowHeight = 18.75
ActiveSheet.Range("F1:J4").Copy ' .Select
' Paste to PowerPoint and position
Set myShape = ppProgram.ActivePresentation.Slides(SlideNum).Shapes.PasteSpecial(ppPasteMetafilePicture, msoFalse)
' Set Dashboard object properties:
myShape.Left = 536 ' 7.44"
myShape.Top = 7 ' 0.1"
' --- Loop through each chart in the Excel worksheet and paste them into the PowerPoint ---
For Each cht In ActiveSheet.ChartObjects
'go to the 1-Pager Slide number where we will update the charts with the Excel Charts
Set activeSlide = ppProgram.ActivePresentation.Slides(SlideNum)
'Copy the chart and paste it into the PowerPoint as a Metafile Picture
cht.Select
ActiveChart.ChartArea.Copy
If cht.Name = "RiskRadar_Chart" Then ' change paste setting only for Radar type chart, to look nicer in PowerPoint
Set myChart = ppProgram.ActivePresentation.Slides(SlideNum).Shapes.PasteSpecial(ppPasteMetafilePicture, msoFalse)
Else
Set myChart = ppProgram.ActivePresentation.Slides(SlideNum).Shapes.PasteSpecial(ppPasteDefault, msoFalse) 'ppPasteShape
End If
'Adjust the positioning of the Chart on Powerpoint Slide , each inch is 72 points
Select Case cht.Name
Case "Timeline_Chart" ' 1 ' Timeline Chart
myChart.Left = 11 ' 0.16"
myChart.Top = 403 ' 5.55"
Case "Budget_Chart" ' 2 ' Man-Hours Chart
myChart.Left = 387 ' 5.37"
myChart.Top = 284 ' 3.94"
Case "Expense_Chart" ' 3 ' Expense Chart
myChart.Left = 387 ' 5.37"
myChart.Top = 347 ' 4.81"
Case "RiskRadar_Chart" ' 4 ' Risk-Radar Chart
myChart.Left = 449 ' 6.23"
myChart.Top = 7 ' 0.1"
End Select
Next
' --- Add Stage Status indicator with Next KD text inside (except PARK) ----
Select Case StageStat
Case "Green"
With activeSlide.Shapes.AddShape(msoShapeOval, 652, 16, 32, 32) ' Left, Top , Width ,Height
.Fill.ForeColor.RGB = RGB(0, 128, 0) ' color Green
.Fill.Solid
.Line.ForeColor.ObjectThemeColor = msoThemeColorText1
.Line.Weight = 0.75
.TextFrame.TextRange.Font.color.RGB = RGB(0, 0, 0) ' Shape Text Color
.TextFrame.TextRange.Characters.Text = nextKD ' Text inside Shape
.TextFrame2.TextRange.Font.Size = 14 ' Adjust Font Size
.TextFrame2.TextRange.Font.Name = "Arial" ' Adjust Font Style
.TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignCenter ' Center Align Text
.TextFrame2.VerticalAnchor = msoAnchorMiddle ' Vertically Align Text to Middle
.TextFrame2.MarginLeft = 0
.TextFrame2.MarginRight = 0
End With
Case "Yellow"
With activeSlide.Shapes.AddShape(msoShapeRectangle, 652, 16, 32, 32) ' Left, Top , Width ,Height
.Fill.ForeColor.RGB = RGB(255, 255, 0) ' color Yellow
.Fill.Solid
.Line.ForeColor.ObjectThemeColor = msoThemeColorText1
.Line.Weight = 0.75
.TextFrame.TextRange.Font.color.RGB = RGB(0, 0, 0) ' Shape Text Color
.TextFrame.TextRange.Characters.Text = nextKD ' Text inside Shape
.TextFrame2.TextRange.Font.Size = 14 ' Adjust Font Size
.TextFrame2.TextRange.Font.Name = "Arial" ' Adjust Font Style
.TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignCenter ' Center Align Text
.TextFrame2.VerticalAnchor = msoAnchorMiddle ' Vertically Align Text to Middle
.TextFrame2.MarginLeft = 0
.TextFrame2.MarginRight = 0
End With
Case "Red"
With activeSlide.Shapes.AddShape(msoShapeIsoscelesTriangle, 652, 16, 36, 36) ' Left, Top , Width ,Height
.Fill.ForeColor.RGB = RGB(255, 0, 0) ' color Red
.Fill.Solid
.Line.ForeColor.ObjectThemeColor = msoThemeColorText1
.Line.Weight = 0.75
.TextFrame.TextRange.Font.color.RGB = RGB(0, 0, 0) ' Shape Text Color
.TextFrame.TextRange.Characters.Text = nextKD ' Text inside Shape
.TextFrame2.TextRange.Font.Size = 14 ' Adjust Font Size
.TextFrame2.TextRange.Font.Name = "Arial" ' Adjust Font Style
.TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignCenter ' Center Align Text
.TextFrame2.VerticalAnchor = msoAnchorMiddle ' Vertically Align Text to Middle
.TextFrame2.MarginLeft = 0
.TextFrame2.MarginRight = 0
.TextFrame2.Column.Number = 2
End With
End Select
Error_PPTSlideNum_Handler:
If Err.Number <> 0 Then
Err.Clear
MsgBox "Project " & ProjectName & " Slide Number " & SlideNum & " not found in selected PowerPoint. " & _
vbCrLf & "Update your Slide Number according to it's position.", vbInformation, "PowerPoint Slide Number Error"
End If
Next ' ProjectCounter = 0 To NumberofProjectShts
AppActivate ("Microsoft PowerPoint")
Set activeSlide = Nothing
Set ppProgram = Nothing
Set ppPres = Nothing
End Sub
你可以上傳一個樣本儀表板的文件。如果它有機密數據,您可以對其進行清理。這將有助於找出編碼的最佳策略。 – skkakkar
繼我之前的評論之後,如果您將用於出口到PPT幻燈片的整張表格上傳至PPT幻燈片並將其清理爲機密數據後,效果會更好。 – skkakkar