Macro muss 2 mal ausgeführt werden
05.02.2022 10:43:24
oraculix
In Meiner Tabelle habe ich in Zeile A1 bis IG Bilder.
diese werden manchmal geändert und dann muss man sie mühsam per Hand einrichten-
Deshalb das untenstehende Macro es Bestimmt die Höhe und Breite der Bilder und Zentriert sie in den Spalten.
Aber ich muss es 2 mal ausführen wenn ich es nur einmal ausführe werden die Bilder nicht Zentriert
beim Zweiten mal schon.
Frage :
Wo liegt der Fehler und wie kann das Macro verkürzen damit es auch beim ersten mal funktioniert
'Alle Bilder Zentrieren und Größe einstellen
Private Sub Worksheet_Activate()
Dim objShape As Shape
For Each objShape In Tabelle5.Shapes
With objShape
If .Type = msoPicture Then
.LockAspectRatio = False
.Left = .TopLeftCell.Left + .TopLeftCell.Width / 2 - .Width / 2
.Top = .TopLeftCell.Top + .TopLeftCell.Height / 2 - .Height / 2
.Height = Application.CentimetersToPoints(4.2) 'Alle Grafiken Gleiche Höhe
.Width = Application.CentimetersToPoints(6.22) ' und Breite
End If
End With
Next
'Und Hier das Ganze nochmal
For Each objShape In Tabelle5.Shapes
With objShape
If .Type = msoPicture Then
.LockAspectRatio = False
.Left = .TopLeftCell.Left + .TopLeftCell.Width / 2 - .Width / 2
.Top = .TopLeftCell.Top + .TopLeftCell.Height / 2 - .Height / 2
.Height = Application.CentimetersToPoints(4.2) 'Alle Grafiken Gleiche Höhe
.Width = Application.CentimetersToPoints(6.22) ' und Breite
End If
End With
Next
Application.ScreenUpdating = True
End Sub
GrußOraculix