AW: Name aus Ausdruck "herauspicken"
26.04.2005 18:04:00
harry
Hi Rainer,
nun ich weiß das dies eine Variable ist, aber diese ist nicht in dieser Routine!
"Left und Len sind in der VBA-Online-Hilfe sehr gut erklärt"
Danke für das Statement !
Weißt du, ich habe da nicht hinein geschaut ....
Hier mal mein code :
-------------------------------------------------------------------------
Option Explicit
Sub PT_Init()
Dim Tabelle As Worksheet
Dim pt As PivotTable
Dim PivotName As String
Dim WrkBook As String
On Error GoTo ErrorMessage
Application.DisplayAlerts = False
Application.EnableEvents = False
On Error Resume Next
WrkBook = ActiveWorkbook.Name
For Each Tabelle In ActiveWorkbook.Worksheets ' Befüllen der Boxen
Tabelle.Activate
Tabelle.Unprotect ("")
TblName = Tabelle.Name ' Speichere aktuellen TabellenNamen
Set pt = ActiveWorkbook.ActiveSheet.PivotTables()
For Each pt In ActiveSheet.PivotTables
PivotName = pt.Name ' und dessen Namen gespeichert
pt.AutoSort xlAscending, pt.SourceName
FPivotVerlinken.ListBox1.AddItem ("[" & WrkBook & "]" & TblName & "!" & PivotName) ' ListBox1 wird befüllt
FPivotVerlinken.ListBox2.AddItem ("[" & WrkBook & "]" & TblName & "!" & PivotName) ' ListBox2 wird befüllt
FPivotVerlinken.ComboBox1.AddItem ("[" & WrkBook & "]" & TblName & "!" & PivotName) ' ComboBox1 wird befüllt
Next pt
Next Tabelle
Application.DisplayAlerts = True
Application.EnableEvents = True
FPivotVerlinken.Show
GoTo Ende
ErrorMessage:
MsgBox ("Es ist ein Fehler aufgetreten!"), vbCritical + vbOKOnly
Ende:
End Sub
--------------------------------------------------------------------
Sub Verlinken()
Dim Tabelle As Worksheet
Dim pt As PivotTable
Dim PivotName As String
Dim i As Integer
Dim Counter As Integer
Dim Master As String
Dim d As String
On Error GoTo ErrorMessage
Application.DisplayAlerts = False
Application.EnableEvents = False
On Error Resume Next
Master = FPivotVerlinken.ComboBox1.Value ' Tabelle die als Master dient
With FPivotVerlinken.ListBox2
For i = 0 To .ListCount - 1 'Durchlaufe ListBox2 bis Ende
If .Selected(i) Then 'Wenn Selektiert
Counter = Counter + 1 'erhöhe Counter um 1
With pt 'gehe zum aktuell markierten PivotTabellenNamen
d = FPivotVerlinken.ListBox2.List(i) 'Name der PivotTabelle in der i-ten position der Liste
'Hier PROBLEM ---------------------------------
.AutoSort xlManual, .SourceName
ActiveSheet.PivotTableWizard SourceType:=xlPivotTable, SourceData:= _
(FPivotVerlinken.ComboBox1.Value)
ActiveSheet.PivotTables("PivotTable7").SmallGrid = False
ActiveSheet.PivotTables("PivotTable7").AddFields RowFields:="1", _
ColumnFields:="12"
Application.CommandBars("PivotTable").Visible = False
---------------------------------------------------
End With
End If
Next i
If (Counter = 0) Or (Master = "") Then
MsgBox "Sie haben entweder keine Tabelle selektiert oder keine Master Tabelle angegeben!", vbInformation + vbOKOnly ' Wenn nichts selektiert
Call PT_Init
End If
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
GoTo Ende:
ErrorMessage: MsgBox " ", vbExclamation + vbOKOnly, "Fehler!"
Ende:
End Sub
------------------------------------------------------------------
Private Sub CommandButton1_Click() ' OK-Button
On Error GoTo Errorhandler
Me.Hide
Call Verlinken
Unload Me
Exit Sub
Errorhandler:
If Err.Number > 0 Then
MsgBox Err.Number & "-->" & Err.Description
Resume Next
End If
End Sub
-----------------------------------------------------
Private Sub CommandButton2_Click() ' Cancel-Button
Unload Me
FPivotVerlinken.Hide
End Sub
------------------------------------------------------