Is there a way to tell PowerPoint not to open Excel when creating charts?

Slide.Shapes.AddChart()Excel opens automatically. Even if I do Chart.ChartData.Workbook.Application.Visible = falseit quickly , it still shows up. This forces you to automate the creation of error-prone charts, as the user should try not to touch the Excel applications that continue to appear.

Opening a presentation with WithWindow = falseanyway will open Excel when creating new charts.

+5
source share
3 answers

This behavior is β€œby design,” and Microsoft is not interested in the change. This is how the user interface works.

, Excel ( interop, OpenXML), () PowerPoint.

MSDN

+8

.

Sub ChartExample()
Dim s As Shape
Set s = Application.Presentations(1).Slides(1).Shapes.AddOLEObject(ClassName:="Excel.Chart")
End Sub

, s.OLEFormat.Object. , Excel, - , . , Powerpoint 2010 , . , -.

: , , - , . .., . , Excel .

Option Explicit
Const xlcolumns = 2
Sub ChartExample()
Dim s As Shape
Dim wb As Object, chart As Object, data As Object
Set s = Application.Presentations(1).Slides(1).Shapes.AddOLEObject(ClassName:="Excel.Chart")
Set wb = s.OLEFormat.Object
Set chart = wb.Sheets(1)
Set data = wb.Sheets(2)
'Set the range for the chart data
chart.setsourcedata Source:=data.Range("A1:C7"), PlotBy:= _
        xlcolumns
'Update data values for the chart
data.Range("B1").Value = "Column Label 1"
data.Range("C1").Value = "Column Label 2"
data.Range("A2:C7").clearcontents
data.Range("A2").Value = "Row Label"
data.Range("B2").Value = 7
data.Range("C2").Value = 11
End Sub
+1

, .

  • Powerpoint VBA " Microsoft Excel 12.0"

  • , excel yuser .

  • VBA excel

  • Add a powerpoint diagram, the user will not be able to see the opening of the excel main sheet when adding the excet graph of the excel tab, which can be controlled using code.

Code example:

Option Explicit

Sub AddExcelChartSample()

    Dim xlApp As Excel.Application, xlWkbk As Excel.Workbook

    Dim pres As PowerPoint.Presentation, sld As PowerPoint.Slide, iCount As Integer, chtShape As PowerPoint.Shape

    'Open up the excel instance and set parameters


    Set xlApp = New Excel.Application
    With xlApp
        .WindowState = xlNormal
        .Top = -1000
        .Left = -1000
        .Height = 0
        .Width = 0
    End With


    Set sld = PowerPoint.ActiveWindow.View.Slide



    For iCount = 1 To 10

        Set chtShape = sld.Shapes.AddChart(xlLine)
        Set xlWkbk = chtShape.Chart.ChartData.Workbook
        With xlWkbk

            .Sheets(1).Range("A2").Value = "Test 1"
            .Sheets(1).Range("A3").Value = "Test 2"
            .Sheets(1).Range("A4").Value = "Test 3"

        End With

        chtShape.Chart.Refresh

        xlWkbk.Close False


    Next iCount


    xlApp.Quit

End Sub
0
source

All Articles