Liebe Profis, leider verstehe ich VBA nicht so gut, um mein Problem selbst zu lösen.
1. Welche Möglichkeit gibt es ein bestimmtes Logo bzw. ein bestimmtes Shape zu schützen. Leider löscht:
With wksResult
For Each sh In .Shapes
sh.Delete
Next
sngLeft = .Columns(2).Left
End With
auch mein Firmenlogo :-)
2. Kann ich mittlerweile irgendwie die Größe der erzeugten Shaps fixieren, sodass sie nicht aus Versehen beim Verschieben vergrößert oder verkleinert werden können?
Anbei der komplette Code:
Option Explicit
Sub Ladung()
Dim sh As Shape, i As Long, j As Long, strTxt As String
Dim sngTop As Single, sngLeft As Single, sngMax As Single
Dim sngWidth As Single, sngHeight As Single
Const DST As Single = 30
Const SCL As Single = 0.5
With wksResult
For Each sh In .Shapes
sh.Delete
Next
sngLeft = .Columns(2).Left
End With
With wksArea
For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
sngTop = wksResult.Rows(7).Top
sngWidth = .Cells(i, 3).Value * SCL
sngHeight = .Cells(i, 2).Value * SCL
strTxt = .Cells(i, 1) & " (" & sngHeight / SCL & "x" & sngWidth / SCL & ")"
Set sh = wksResult.Shapes.AddShape(1, sngLeft, sngTop, sngWidth, DST)
sh.TextFrame.Characters.Text = strTxt
sh.TextFrame.Characters.Font.FontStyle = "Fett"
sh.Fill.ForeColor.SchemeColor = 8 'Fahrerkabine
sh.TextFrame.HorizontalAlignment = xlHAlignCenter
sh.TextFrame.VerticalAlignment = xlVAlignCenter
sngTop = sngTop + DST
Set sh = wksResult.Shapes.AddShape(1, sngLeft, sngTop, sngWidth, sngHeight)
sh.Fill.ForeColor.SchemeColor = 1
sngLeft = sngLeft + sngWidth + DST
sngMax = IIf(sngMax < sngHeight, sngHeight, sngMax)
Next
End With
With wksCargo
sngTop = sngTop + sngMax + DST
sngLeft = wksResult.Columns(2).Left
For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
sngHeight = .Cells(i, 2).Value * SCL
sngWidth = .Cells(i, 3).Value * SCL
strTxt = .Cells(i, 1) & vbLf & sngHeight / SCL & "x" & sngWidth / SCL
strTxt = strTxt & vbLf & .Cells(i, 4) '"Bemerkung"
Set sh = wksResult.Shapes.AddShape(1, sngLeft, sngTop, sngWidth, sngHeight)
sh.TextFrame.Characters.Text = strTxt
sh.Fill.ForeColor.SchemeColor = 8
sh.TextFrame.HorizontalAlignment = xlHAlignCenter
sh.TextFrame.VerticalAlignment = xlVAlignCenter
sh.ZOrder 0
sngTop = sngTop + sngHeight + DST
Next
End With
Set sh = Nothing
wksResult.Activate
ActiveWindow.DisplayGridlines = False
End Sub
|