AW: Pivotcache.Sourcedata
11.01.2010 16:09:26
fcs
Hallo David,
nach ein paar Tagen wandern alle älteren Beiträge ins Archiv, deswegen ist dein Beitrag "verschwunden".
zu deinem Problem:
Wenn die Quelldatei der Pivottabelle geöffnet ist, dann darf in der Pivot-Quelle kein Pfad mit angegeben werden.
Zusätzlich sollte sichergestellt sein, dass Quelldatei und Datei mit Pivottabellen geöffnet sind.
Gruß
Franz
Sub Pivot_Quelle()
Dim i As Byte, Zeilen As Double, Spalten As Double
Dim wbSource As Workbook, wks As Worksheet, oPVCache As PivotCache
Dim sDateiSource As String, sSheetSource As String, sDateiPivot As String
sDateiSource = "Materialabweichung komplett.xls"
sSheetSource = "SAPBW_DOWNLOAD"
sDateiPivot = "Verluste.xls"
If checkWorkbook(sWorkbookName:=sDateiPivot) = True Then
If checkWorkbook(sWorkbookName:=sDateiSource) = True Then
Set wbSource = Workbooks(sDateiSource)
Set wks = wbSource.Worksheets(sSheetSource)
Zeilen = wks.UsedRange.Rows.Count
Spalten = wks.UsedRange.Columns.Count
With Workbooks(sDateiPivot)
For i = 1 To .PivotCaches().Count
Set oPVCache = .PivotCaches(i)
With wks
oPVCache.SourceData = "'[" & wbSource.Name & "]" & .Name & "'!" _
& .Range(.Cells(1, 1), .Cells(Zeilen, Spalten)).Address(ReferenceStyle:=xlR1C1)
End With
Next
End With
Else
MsgBox "Bitte vorm Makro-Start Datei """ & sDateiSource & """ öffnen!", _
vbInformation + vbOKOnly, "Aktualisierung Pivot-Sorce-Data"
End If
Else
MsgBox "Bitte vorm Makro-Start Datei """ & sDateiPivot & """ öffnen!", _
vbInformation + vbOKOnly, "Aktualisierung Pivot-Source-Data"
End If
Set wbSource = Nothing: Set wks = Nothing: Set oPVCache = Nothing
End Sub
Function checkWorkbook(sWorkbookName As String)
'Prüft ob workbook geöffnet ist
Dim wb As Workbook
For Each wb In Workbooks
If LCase(wb.Name) = LCase(sWorkbookName) Then checkWorkbook = True
Next
End Function