【发布时间】:2020-08-17 21:10:43
【问题描述】:
尊敬的 Stackoverflow 社区,
我不知道这是否正确,并且想要一些关于如何在 MSGraph 对象上使用 Late binding 的指导。
我已经使用了这个Early binding,它可以工作,但现在我想使用后期绑定,这样我就可以避免添加Microsoft Graph 16.0 Object Library。
以下代码有效,但需要Microsoft Graph 16.0 Object Library
早期绑定:
Private Sub Form_Open(Cancel As Integer)
Dim myChart As Graph.Chart
Dim myChartSeries As Graph.Series
Dim mySeriesDataLabel As Graph.DataLabel
Set myChart = Me.myGraph.Object
For Each myChartSeries In myChart.SeriesCollection
For Each mySeriesDataLabel In myChartSeries.DataLabels
mySeriesDataLabel.Font.Name = "Times New Roman"
mySeriesDataLabel.Font.FontStyle = "Normal"
mySeriesDataLabel.Font.Size = 8
Next mySeriesDataLabel
Next myChartSeries
With Me.myGraph.Axes(1).TickLabels.Font
.Name = "Times New Romans"
.FontStyle = "Normal"
.Size = 8
End With
With Me.myGraph.Axes(2).TickLabels.Font
.Name = "Times New Romans"
.FontStyle = "Normal"
.Size = 8
End With
End Sub
后期绑定: -Approach
我已经尝试过这段代码,似乎可以正常工作,但我不确定这是否是正确的做法。 有人可以指导我采取正确的方法吗?
Private Sub Form_Open(Cancel As Integer)
Dim myChart As Object
Set myChart = Me.myGraph.Object
Dim myChartSeries As Variant
Set myChartSeries = New VBA.Collection
Dim mySeriesDataLabel As Variant
Set myChartSeries = New VBA.Collection
For Each myChartSeries In myChart.SeriesCollection
For Each mySeriesDataLabel In myChartSeries.DataLabels
mySeriesDataLabel.Font.Name = "Times New Roman"
mySeriesDataLabel.Font.FontStyle = "Normal"
mySeriesDataLabel.Font.Size = 8
Next mySeriesDataLabel
Next myChartSeries
With Me.myGraph.Axes(1).TickLabels.Font
.Name = "Times New Romans"
.FontStyle = "Normal"
.Size = 8
End With
With Me.myGraph.Axes(2).TickLabels.Font
.Name = "Times New Romans"
.FontStyle = "Normal"
.Size = 8
End With
End Sub
【问题讨论】: