VBA PP auf kürzlich erstelltes Shape zugreifen
08.10.2014 15:30:58
Paddy_P
ich schreibe gerade an einem Skript bei dem ich über VBA aus Excel einen Range Kopiere und diesen in Powerpoint einfüge.
Sobald ich versuche das erstellte Shape anzusprechen (Tabelle 1) gibt es eine Fehlermeldung, dass dieses Shape nicht vorhanden wäre.
Das würde ich ja akzeptieren, aber gehe ich in den Debugmodus und drücke F8, so funktioniert es plötzlich und VBA findet das Shape.
Mein Code ist dieser:
Option Explicit
Sub Einfuegen(LC, pptPres, SS, lc, EDB)
Dim msE As Object
Dim wbk As Workbook
Dim wsh As Worksheet
Dim objPPT As Object
Dim wsh_List As Variant
Dim i As Long
Dim j As Long
wsh_List = Array("Datei 1", "Datei 2", "Datei 3", "Datei 4")
Set objPPT = CreateObject("Powerpoint.Application")
Set msE = GetObject(, "Excel.Application")
For Each wbk In msE.Workbooks
For Each wsh In wbk.Worksheets
For i = 0 To 3
If wsh.Name = wsh_List(i) Then
Const a = 4
Const b = 5
Const c = 4
Const d = 6
Dim Sld_list As Variant
Dim LC_list As Variant
Sld_list = Array(a, b, c, d)
LC_list = Array("Data 1", "Data 2", "Data 3", "Data 4")
For j = 0 To 3
If InStr(LC, LC_list(j)) Then
wsh.Range("C4:" & Chr(64 + lc) & "5").Copy
pptPres.Slides(Sld_list(j)).Select
objPPT.CommandBars.ExecuteMso ("PasteSourceFormatting")
With pptPres.Slides(Sld_list(j)).Shapes("Tabelle 1")
' HIER STELLT SICH VBA ETWAS QUER...
.Left = 20
.Top = 94
.Width = 518
.Height = 28
End With
If InStr(LC, "Data 1") Then
wsh.Range(Chr(67) & SS & ":" & Chr(64 + lc) & _
EDB + 1).Copy
objPPT.CommandBars.ExecuteMso ("PasteSourceFormatting")
Else
wsh.Range(Chr(67) & SS & ":" & Chr(64 + lc) & _
EDB).Copy
objPPT.CommandBars.ExecuteMso ("PasteSourceFormatting")
End If
With pptPres.Slides(Sld_list(j)).Shapes("Tabelle 2")
' HIER EBENFALLS DAS GLEICHE PROBLEM...
.Left = 20
.Top = 150
.Width = 518
.Height = 322
End With
Exit Function
End If
Next
End If
Next
Next
Next
End Sub
Als kurze Beschreibung noch zum Skript:Ich möchte hier mehrere Strings miteinander vergleichen und Anhand derer verschiedene Auswertungen bekommen (also mal eine andere Spalte etc.)
Ich hoffe Skript ist nicht zu verwirrend und mir kann jem. helfen...?
Danke schon mal!