mein Problem. Wenn zum Beispiel die Zelle A1 die Hintergrundfarbe "Grün" hat, soll ein gezeichneter Kreis auf einem beliebigen Arbeitsmappe auch grün werden! Wie kann ich sowas realisieren?
Vielen Dank schonmal!
Sub b()
Dim cell1 As Range
Dim shape1 As shape
Set cell1 = Range("a1")
Set shape1 = ActiveSheet.Shapes(1)
shape1.OLEFormat.Object.Interior.Color = cell1.Interior.Color
End Sub
Sub c()
Dim shp As shape
For Each shp In ActiveSheet.Shapes
shp.OLEFormat.Object.Interior.Color = Range(shp.Name & "_color").Interior.Color
Next shp
End Sub
Also z.B. Zelle 1 hat Name "Circle1_color" und diese Zelle wird den Shape "Circle1" faerben...
Private Sub SwitchStoplight(ByRef io_stoplightSwitcher As Range)
On Error GoTo Err_SwitchStoplight
If (ResetStoplight(io_stoplightSwitcher) = True) Then
Select Case io_stoplightSwitcher.Interior.Color
Case vbRed
m_redLightShape.OLEFormat.Object.Interior.Color = vbRed
Case vbYellow
m_yellowLightShape.OLEFormat.Object.Interior.Color = vbYellow
Case vbGreen
m_greenLightShape.OLEFormat.Object.Interior.Color = vbGreen
Case Else
MsgBox "Unknown stoplight color : " & io_stoplightSwitcher.Interior.Color, vbExclamation, "Switching stoplight failed"
End Select
Else
End If
Exit Sub
Err_SwitchStoplight:
MsgBox Err.Description, vbCritical, "Error in function SwitchStoplight"
End Sub
Private Function ResetStoplight(ByRef io_stoplightSwitcher As Range) As Boolean
ResetStoplight = False
' nur shapes auf dem selben sheet, wo auch der stoplight-switcher liegt
With io_stoplightSwitcher.Worksheet
On Error Resume Next
Set m_greenLightShape = .Shapes(GREEN_LIGHT)
Set m_yellowLightShape = .Shapes(YELLOW_LIGHT)
Set m_redLightShape = .Shapes(RED_LIGHT)
On Error GoTo Err_ResetStoplight
' alle lights-shapes muessen vorhanden sein
If (m_greenLightShape Is Nothing Or m_yellowLightShape Is Nothing Or m_redLightShape Is Nothing) Then
MsgBox "Stoplight reset function failed. Some stoplight-shape was not found in the collection.", vbCritical, "Stoplight reset failed"
Exit Function
End If
m_greenLightShape.OLEFormat.Object.Interior.Color = vbWhite
m_yellowLightShape.OLEFormat.Object.Interior.Color = vbWhite
m_redLightShape.OLEFormat.Object.Interior.Color = vbWhite
ResetStoplight = True
End With
Exit Function
Err_ResetStoplight:
MsgBox Err.Description, vbCritical, "Error in function ResetStoplight"
End Function
Public Sub Main()