Excel 是否可以更新';Microsoft PowerPoint中的图表';从PowerPoint用户表单中输入的数据

Excel 是否可以更新';Microsoft PowerPoint中的图表';从PowerPoint用户表单中输入的数据,excel,powerpoint,userform,vba,Excel,Powerpoint,Userform,Vba,图表是通过Microsoft PowerPoint中的图表功能创建的,我们希望通过使用PowerPoint用户表单来控制图表的更新方式。执行例程时,是否有一行代码可以指向Microsoft PowerPoint图表中名为DVPVreport的工作表?下面的代码不考虑 DVPVReals>代码>位于微软PowerPoint中的图表中。我们尝试执行以下代码: Set ws = 'Chart In MicrosoftPowerPoint!'.Worksheets(DVPVreport) 但是没有成

图表是通过Microsoft PowerPoint中的图表功能创建的,我们希望通过使用PowerPoint用户表单来控制图表的更新方式。执行例程时,是否有一行代码可以指向Microsoft PowerPoint图表中名为
DVPVreport
的工作表?下面的代码不考虑<代码> DVPVReals>代码>位于微软PowerPoint中的图表中。我们尝试执行以下代码:

Set ws = 'Chart In MicrosoftPowerPoint!'.Worksheets(DVPVreport) 
但是没有成功

Private Sub AddDVSetUp_Click()

   Dim ws As Worksheet
   Set ws = Worksheets("DVPVreport")

   ws.Cells(3, 4).Value = Gate2Date.Value
   Unload M

   ws.Cells(3, 5).Value = Gate3Date.Value
   Unload M

End Sub

是的,这是可能的。试试这个:

Dim sl As Slide
Set sl = ActivePresentation.Slides(1)

Dim xlWB As Object
Dim sh As Shape, ch As Chart

For Each sh In sl.Shapes
    If sh.Type = msoChart Then
        Set ch = sh.Chart
        Set xlWB = ch.ChartData.Workbook
        With xlWB.Sheets(1) '/* It has only 1 sheet so this will be fine */
            '/* Do the changes you want here */
            .Range("B2").Value = 4.2
        End With
    End If
Next
Set ch = Nothing: Set xlWB = Nothing: Set sl = Nothing '/* clean up */
现在,如果您已经知道对象的索引或名称,您可以简单地:

Dim sl As Slide
Set sl = ActivePresentation.Slides(1)

Dim xlWB As Object
Dim sh As Shape

Set sh = sl.Shapes("Chart 1")
Set xlWB = sh.Chart.ChartData.Workbook

With xlWB.Sheets(1)
    .Range("B2").Value = 4.2
End With

重要提示:小心不要破坏源数据布局。执行此操作时,由于某种原因,它会将图表与
图表数据取消关联。

是,这是可能的。试试这个:

Dim sl As Slide
Set sl = ActivePresentation.Slides(1)

Dim xlWB As Object
Dim sh As Shape, ch As Chart

For Each sh In sl.Shapes
    If sh.Type = msoChart Then
        Set ch = sh.Chart
        Set xlWB = ch.ChartData.Workbook
        With xlWB.Sheets(1) '/* It has only 1 sheet so this will be fine */
            '/* Do the changes you want here */
            .Range("B2").Value = 4.2
        End With
    End If
Next
Set ch = Nothing: Set xlWB = Nothing: Set sl = Nothing '/* clean up */
现在,如果您已经知道对象的索引或名称,您可以简单地:

Dim sl As Slide
Set sl = ActivePresentation.Slides(1)

Dim xlWB As Object
Dim sh As Shape

Set sh = sl.Shapes("Chart 1")
Set xlWB = sh.Chart.ChartData.Workbook

With xlWB.Sheets(1)
    .Range("B2").Value = 4.2
End With

重要提示:小心不要破坏源数据布局。当您执行此操作时,出于某种原因,它会将图表与
图表数据取消关联。

非常有效。为了提高演示文稿中此幻灯片的灵活性,是否有与ActivePresentation.slide(1)相关的(1)解决方案?有时此幻灯片不是演示文稿中的第一张幻灯片。它可以在幻灯片8到15的任何地方。@M.Boes我把这部分留给你:)。如果您知道图表对象的具体名称,那么您可以通过所有幻灯片进行简单循环,并检查图表所在的位置。我使用了
ActivePresentation.Slides(1)
进行演示,效果非常好。为了提高演示文稿中此幻灯片的灵活性,是否有与ActivePresentation.slide(1)相关的(1)解决方案?有时此幻灯片不是演示文稿中的第一张幻灯片。它可以在幻灯片8到15的任何地方。@M.Boes我把这部分留给你:)。如果您知道图表对象的具体名称,那么您可以通过所有幻灯片进行简单循环,并检查图表所在的位置。我使用了
ActivePresentation.Slides(1)
进行演示。