ThinkCell Automation通过VBA

时间:2018-02-15 17:01:48

标签: vba charts powerpoint

我正在寻找VBA代码来创建excel范围的思维单元格图。

我在互联网上找到的只是VBA代码,通过它我可以更新命名的thinkcell图表。

但是我希望宏从我定义的范围内创建一个新的powerpoint和新的thinkcell图表。

这可能吗?

以下是我发现的代码,通过该代码可以更新Thinkcell图表,但不会创建新的thinkcell图表。

Sub UpdateThinkCellChart(Rng As Range, sChartName As String)


'Get the think-cell add-in object
Dim tcaddin As Object
Dim ppapp As Object
Dim pres As Object

Set tcaddin = Application.COMAddIns("thinkcell.addin").Object


'Set PowerPoint instance
'Set ppapp = New PowerPoint.Application

On Error Resume Next
Set ppapp = GetObject(, "Powerpoint.Application")
On Error GoTo 0

'Create PowerPoint presentation if none is open:
If ppapp Is Nothing Then
MsgBox "No PowerPoint presentation is open. Please open the relevant presentation and ensure that you have pre-assigned chart names to your ThinkCell charts"
Exit Sub
End If

'Dim pres As PowerPoint.Presentation

Set pres = ppapp.ActivePresentation


' The name sChartName must have been previously assigned to the chart using
' the control in the floating toolbar (left-click on the Think-Cell chart to see this)
' The final argument indicates whether the data range is transposed or not.
Call tcaddin.UpdateChart(pres, sChartName, Rng, False)


End Sub

Sub CopyToTC_ChartNo1()
Dim Rng As Range, sRange As String, sChartName As String

'Insert values:
sRange = "C21:F25"
sChartName = "ChartNo1"


Set Rng = ActiveSheet.Range(sRange)

Call UpdateThinkCellChart(Rng, sChartName)

End Sub

0 个答案:

没有答案