0
我試圖創建一個makro,以便從存儲在csv文件中的數據自動生成powerpoint 2010中的圖表。我得到了生成圖表並閱讀csv文件,但現在我用顯示數據來填充。VBA Powerpoint 2010根據csv數據創建圖表
這裏是到目前爲止我的代碼:
Sub CreateChart()
Dim myChart As Chart
Dim gChartData As ChartData
Dim gWorkBook As Excel.Workbook
Dim gWorkSheet As Excel.Worksheet
Dim strPath As String
Dim lngLastRow As Long
Dim mySystemFileObject
' Create the chart and set a reference to the chart data.
Set myChart = ActivePresentation.Slides(1).Shapes.AddChart.Chart
Set gChartData = myChart.ChartData
' read the csv file
strPath = "C:\path\to\my\data.csv"
' Set the Workbook and Worksheet references.
Set gWorkBook = gChartData.Workbook
Set gWorkSheet = gWorkBook.Worksheets(1)
With gWorkSheet.QueryTables.Add(Connection:="TEXT;" & strPath, Destination:=gWorkSheet.Range("A1"))
.TextFileDecimalSeparator = "."
.TextFileThousandsSeparator = " "
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = True
.Refresh
End With
gWorkBook.RefreshAll
' Does not work, returns Runtime Error 1004
'gWorkSheet.ListObjects("Tabelle1").Resize gWorkSheet.Range("A1:G5")
myChart.SetSourceData ("='Tabelle1'!A7:G74")
myChart.Refresh
'gWorkSheet.Range("A7:G74").Select
' Clean up the references.
Set gWorkSheet = Nothing
' gWorkBook.Application.Quit
gWorkBook.Close
Set gChartData = Nothing
Set myChart = Nothing
End Sub
現在的問題是選擇範圍A1:G74與VBA和在圖表中顯示的數據。可能我只是錯過了正確的功能。 任何想法或幫助表示讚賞!
最好的問候, 吉姆