Select 使用 vba 的 powerpoint 图表中的新数组?
Select new array in powerpoint chart using vba?
我在 powerpoint 中有一个图表,在他的数据中有很多行,我想做的是 VBA select 只是 VBA 的特定行,可以你帮我?谢谢!
稍微修改:
- 使用
"Bus 1"
到 "Bus 22"
创建并填充 ComboBox1
。
Private Sub ComboBox1_DropButtonClick()
Dim i As Integer
With ComboBox1
If .ListCount = 0 Then
For i = 1 To 22
.AddItem "Bus " & i, i - 1
Next i
End If
End With
End Sub
然后不隐藏行,而是使用 Chart.SetSourceData
实际更改图表的源数据。为此:
- 在工具 > 引用.
下添加对 Microsoft Excel 对象库 的引用
Find
Worksheet
上的 ComboBox1.Value
并获取相应的源数据范围。
- 然后将
SetSourceData
与对 Worksheet
的 Name
和源数据 的 Address
的串联引用一起使用
Private Sub ComboBox1_Change()
Dim shp As Shape: Set shp = ActivePresentation.SlideShowWindow.View.Slide.Shapes("Chart 5") ' Change to your chart name
Dim rng As Excel.Range, dataRng As Excel.Range
Dim ws As Excel.Worksheet: Set ws = shp.Chart.ChartData.Workbook.Sheets(1)
With ws
Set rng = .Cells.Find(ComboBox1.Value)
If Not rng Is Nothing Then
' Data rng starts 1 column to the right and spans 2 rows
Set dataRng = .Range(rng.Offset(, 1), rng.End(xlToRight).Offset(1))
shp.Chart.SetSourceData Source:="='" & .Name & "'!" & dataRng.Address, PlotBy:=xlRows
End If
End With
End Sub
我在 powerpoint 中有一个图表,在他的数据中有很多行,我想做的是 VBA select 只是 VBA 的特定行,可以你帮我?谢谢!
稍微修改
- 使用
"Bus 1"
到"Bus 22"
创建并填充ComboBox1
。
Private Sub ComboBox1_DropButtonClick()
Dim i As Integer
With ComboBox1
If .ListCount = 0 Then
For i = 1 To 22
.AddItem "Bus " & i, i - 1
Next i
End If
End With
End Sub
然后不隐藏行,而是使用
Chart.SetSourceData
实际更改图表的源数据。为此:- 在工具 > 引用. 下添加对 Microsoft Excel 对象库 的引用
Find
Worksheet
上的ComboBox1.Value
并获取相应的源数据范围。- 然后将
SetSourceData
与对Worksheet
的Name
和源数据 的
Address
的串联引用一起使用
Private Sub ComboBox1_Change()
Dim shp As Shape: Set shp = ActivePresentation.SlideShowWindow.View.Slide.Shapes("Chart 5") ' Change to your chart name
Dim rng As Excel.Range, dataRng As Excel.Range
Dim ws As Excel.Worksheet: Set ws = shp.Chart.ChartData.Workbook.Sheets(1)
With ws
Set rng = .Cells.Find(ComboBox1.Value)
If Not rng Is Nothing Then
' Data rng starts 1 column to the right and spans 2 rows
Set dataRng = .Range(rng.Offset(, 1), rng.End(xlToRight).Offset(1))
shp.Chart.SetSourceData Source:="='" & .Name & "'!" & dataRng.Address, PlotBy:=xlRows
End If
End With
End Sub