AddLabel: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Thomas (Diskussion | Beiträge) KKeine Bearbeitungszusammenfassung |
Thomas (Diskussion | Beiträge) K (Verbessertes Programm) |
||
| Zeile 1: | Zeile 1: | ||
Folgendes VBA-Unterprogramm fügt in alle Charts einer Excel-Datei ein Textfeld / Label rechts oben mit dem aktuellen Monat (Januar, Februar ...) und Jahr (vierstellig) ein. | Folgendes VBA-Unterprogramm '''SetDateInDiagram()''' fügt in alle Charts einer Excel-Datei ein Textfeld / Label rechts oben mit dem aktuellen Monat (Januar, Februar ...) und Jahr (vierstellig) ein. Mit der Funktion '''CheckLabelExists(...)''' wird geprüft, ob ein Label mit dem Namen "Stand" bereits existiert. | ||
<pre> | <pre> | ||
Sub | Private Function CheckLabelExists(argChart As Object, argName As String) As Boolean | ||
Dim obj As Object | |||
CheckLabelExists = False | |||
For Each obj In argChart.Shapes | |||
If UCase(obj.Name) = UCase(argName) Then CheckLabelExists = True: Exit Function | |||
Next obj | |||
End Function | |||
Sub SetDateInDiagram() | |||
' | |||
' Stand Makro | |||
' Einfügen des Standes des Diagrames | |||
' | |||
Dim mySheet As Worksheet | Dim mySheet As Worksheet | ||
| Zeile 12: | Zeile 28: | ||
Set myChart = mySheet.ChartObjects(1).Chart | Set myChart = mySheet.ChartObjects(1).Chart | ||
If Not CheckLabelExists(myChart, "Stand") Then | |||
With myChart.Shapes.AddLabel(msoTextOrientationHorizontal, 380, 4, 144, 20) | |||
.Name = "Stand" | |||
.TextFrame.Characters.Text = Format(Date, "mmmm yyyy") | |||
.TextFrame.Characters.Font.Size = 12 | |||
.TextFrame.Characters.Font.Bold = True | |||
.TextFrame.HorizontalAlignment = xlHAlignRight | |||
End With | |||
Else | |||
myChart.Shapes("Stand").TextFrame.Characters.Text = Format(Date, "mmmm yyyy") | |||
myChart.Shapes("Stand").TextFrame.HorizontalAlignment = xlHAlignRight | |||
End If | |||
End If | End If | ||
Version vom 2. November 2016, 09:55 Uhr
Folgendes VBA-Unterprogramm SetDateInDiagram() fügt in alle Charts einer Excel-Datei ein Textfeld / Label rechts oben mit dem aktuellen Monat (Januar, Februar ...) und Jahr (vierstellig) ein. Mit der Funktion CheckLabelExists(...) wird geprüft, ob ein Label mit dem Namen "Stand" bereits existiert.
Private Function CheckLabelExists(argChart As Object, argName As String) As Boolean
Dim obj As Object
CheckLabelExists = False
For Each obj In argChart.Shapes
If UCase(obj.Name) = UCase(argName) Then CheckLabelExists = True: Exit Function
Next obj
End Function
Sub SetDateInDiagram()
'
' Stand Makro
' Einfügen des Standes des Diagrames
'
Dim mySheet As Worksheet
Dim myChart As Chart
For Each mySheet In Worksheets
If mySheet.ChartObjects.Count > 0 Then
Set myChart = mySheet.ChartObjects(1).Chart
If Not CheckLabelExists(myChart, "Stand") Then
With myChart.Shapes.AddLabel(msoTextOrientationHorizontal, 380, 4, 144, 20)
.Name = "Stand"
.TextFrame.Characters.Text = Format(Date, "mmmm yyyy")
.TextFrame.Characters.Font.Size = 12
.TextFrame.Characters.Font.Bold = True
.TextFrame.HorizontalAlignment = xlHAlignRight
End With
Else
myChart.Shapes("Stand").TextFrame.Characters.Text = Format(Date, "mmmm yyyy")
myChart.Shapes("Stand").TextFrame.HorizontalAlignment = xlHAlignRight
End If
End If
Next
End Sub