我想使用调用Excel中的vba代码的Powershell脚本自动刷新数据透视表。 我的powershell代码是th。使用VBA刷新数据透视表
$excel = new-object -comobject excel.application
$workbook = $excel.workbooks.open("$para_temp\RapportPalettes.xlsm")
$worksheet = $workbook.worksheets.item("source")
$excel.Run('Import')
$worksheet = $workbook.worksheets.item("TCD")
$excel.Run('MAJ')
第一个宏“导入”工作得很好。但是,第二个“少校”,随着源新数据刷新数据透视表不
我第一次尝试这个宏少将:
Sub maj()
Dim pt As PivotTable
Set pt = ActiveSheet.PivotTables("TCD")
pt.RefreshTable
End Sub
我没有得到任何错误,但我pivote表没有刷新,我必须手动完成。
然后我试图这一个来改变数据的枢轴表的源:
Sub MAJ()
Dim sht As Worksheet
Dim SrcData As String
Dim pvtCache As PivotCache
'Determine the data range you want to pivot
Set sht = ThisWorkbook.Worksheets("Source")
SrcData = sht.Name & "!" & Range("A1:Z10000").Address(ReferenceStyle:=xlR1C1)
'Create New Pivot Cache from Source Data
Set pvtCache = ActiveWorkbook.PivotCaches.Create(_
SourceType:=xlDatabase, _
SourceData:=SrcData)
'Change which Pivot Cache the Pivot Table is referring to
Worksheets("TCD").Activate
ActiveSheet.PivotTables("TCD").ChangePivotCach (pvtCache)
End Sub
但是我有一个438错误在VBA:对象不支持此属性或方法,用于该行
ActiveSheet.PivotTables("TCD").ChangePivotCach (pvtCache)
请帮忙吗?
编辑:
编辑: 其实宏的工作,我通过创建一个按钮调用它进行了测试。 当我使用PowerShell
它不应该是“.ChangePivotCache”,而不是“.ChangePivotCach”? – thepip3r
是的,这只是一个小费错误。我仍然得到相同的错误:对象不支持此属性或方法,并在同一行 –