我在PowerPoint中引用了一个引用打开的excel工作簿的代码,但每次我将PPT-Chart数据表设置为等于工作簿中的某个范围时,都会出现另一个excel实例。有谁知道为什么会这样?
我可以无效地调用子例程,还是我没有正确处理实例/对象?
Sub Main()
Dim xlWorkBook As Object
Dim Template As String
Dim lDate As String
Dim company As String
Dim Period as String
'This is the excel data file
path2 = "T:\User\Distributor\Distributor Test.xlsm" ' for testing only
'This is the template file
Template = ActivePresentation.FullName
Set xlWorkBook = GetObject(path2) 'gets the excel object
company = xlWorkBook.Sheets(1).Range("A1").Value2
Period = Left(xlWorkBook.Sheets(1).Range("A2").Value2, 2)
lDate = Trim(xlWorkBook.Sheets(1).Range("A3").Value2)
Call Slide_3(xlWorkBook, company, lDate, Period, Template)
End Sub
Sub Slide_3(xlWorkBook, company, lDate, Period, Template)
For Each oSH In Presentations(Template).Slides(3).Shapes
Select Case oSH.Name
Case "DOLLARS_3"
With oSH.Chart.ChartData
'this updates the values in the datasheet and is the line that causes the new instance of excel.
.Workbook.Sheets(1).Range("A2:B8").Value2 = xlWorkBook.Sheets(48).Range("A2:B8").Value
End With
End Select
Next oSH
End Sub