簡體   English   中英

將 Excel 圖表作為圖片導出到 PowerPoint

[英]Export Excel charts as pictures to PowerPoint

我在 excel 工作簿中,每張一張圖表和多張圖表,我正在嘗試將所有圖表作為圖片導出到 PowerPoints 問題是我擁有的當前代碼不起作用

Sub TEST_ExportChartsToPowerPoint_SingleWorkbook()
    'Declare PowerPoint Object Variables
    Dim pptApp As PowerPoint.Application
    Dim pptPres As PowerPoint.Presentation
    Dim pptSlide As PowerPoint.Slide
    Dim SldIndex As Integer
    'Declare Excel Object Variables
    Dim Chrt As ChartObject
    'Dim Chrt As ChartArea
    Dim WrkSht As Worksheet
    
    'Create a new instance of PowerPoint
    Set pptApp = New PowerPoint.Application
        pptApp.Visible = True

    'Create a new Presentation within the PowerPoint Application
    Set pptPres = pptApp.Presentations.Add

    'Create an index handler for the slide creation
    SldIndex = 1
    
    'Loop through all of the worksheets in the active work book
    For Each WrkSht In Worksheets
        'WrkSht.Select

        ActiveChart.ChartArea.Select
        ActiveChart.ChartArea.Copy
                       
        'Create a new slide, set the layout to blank, and paste the chart on the slide
        Set pptSlide = pptPres.Slides.Add(SldIndex, ppLayoutBlank)
        pptSlide.Shapes.Paste
                
        'Increment our slide index
        SldIndex = SldIndex + 1
    
    Next WrkSht
              
End Sub

一個問題是您設置了With語句,但您從未使用過它。 ActiveChartWorkbook object 的屬性,它是代碼中的變量WrkSht 將這些行更改為具有. 在他們面前。

改變這兩行

ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy

.ActiveChart.ChartArea.Select
.ActiveChart.ChartArea.Copy

在您的With塊中。

無法保證這是您的代碼的(唯一)問題,因為您沒有告訴我們發生了什么錯誤,或者您的代碼如何沒有給您預期的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM