Ich beurteile Menschen nicht nach Aussehen, Hautfarbe oder Religion. Sondern wie sie sich benehmen, wenn eine zweite Kasse geöffnet wird.
Das ist bösartig! In einem Exceldokument sollen Werte von Eigenschaftsfeldern, die von SAP kommen, in die Kopfzeile geschrieben werden. Also von:
Nach:
Der Befehl für diese Felder ist schnell gefunden:
ContentTypeProperties(„Target group“)
Das Makro:
Dim strTitle As String
Dim strLocation As String
Dim strTarget As String
Dim strType As String
strTitle = ThisWorkbook.BuiltinDocumentProperties("Title").Value
strLocation = ThisWorkbook.ContentTypeProperties("Location").Value
strTarget = ThisWorkbook.ContentTypeProperties("Target group").Value
strType = ThisWorkbook.ContentTypeProperties("Document type").Value
If strTitle <> "" Then strTitle = " " & strTitle
If strLocation <> "" Then strLocation = " " & strLocation
If strTarget <> "" Then strTarget = " " & strTarget
If strType <> "" Then strType = " " & strType
With ActiveSheet.PageSetup
.LeftHeader = Replace(.LeftHeader, "Title", "Title" & strTitle)
.LeftHeader = Replace(.LeftHeader, "Location", "Location" & strLocation)
.LeftHeader = Replace(.LeftHeader, "Target group", "Target group" & strTarget)
.LeftHeader = Replace(.LeftHeader, "Document type", "Document type" & strType)
End With
Ein Durchlauf mit leeren Feldern – klappt! Ein Durchlauf mit Daten bringt die Fehlermeldung 13: Typen unverträglich. Ich stutze. Ich untersuche die Inhalte. tatsächlich: die Daten, die aus Sharepoint kommen, sind keine Texte, sondern Datenfelder. Bestehend aus zwei Werten: Inhalt und ID. Sieht man aber nicht:
Nun das kann man abprüfen:
Dim strTitle As String
Dim strLocation As String
Dim strTarget As String
Dim strType As String
If TypeName(ThisWorkbook.BuiltinDocumentProperties("Title").Value) = "String()" Then
If UBound(ThisWorkbook.BuiltinDocumentProperties("Title").Value) >= 0 Then
strTitle = ThisWorkbook.BuiltinDocumentProperties("Title").Value(0)
End If
ElseIf TypeName(ThisWorkbook.BuiltinDocumentProperties("Title").Value) = "String" Then
strTitle = ThisWorkbook.BuiltinDocumentProperties("Title").Value
End If
If TypeName(ThisWorkbook.ContentTypeProperties("Location").Value) = "String()" Then
If UBound(ThisWorkbook.ContentTypeProperties("Location").Value) >= 0 Then
strLocation = ThisWorkbook.ContentTypeProperties("Location").Value(0)
End If
ElseIf TypeName(ThisWorkbook.ContentTypeProperties("Location").Value) = "String" Then
strLocation = ThisWorkbook.ContentTypeProperties("Location").Value
End If
If TypeName(ThisWorkbook.ContentTypeProperties("Target group").Value) = "String()" Then
If UBound(ThisWorkbook.ContentTypeProperties("Target group").Value) >= 0 Then
strTarget = ThisWorkbook.ContentTypeProperties("Target group").Value(0)
End If
ElseIf TypeName(ThisWorkbook.ContentTypeProperties("Target group").Value) = "String" Then
strTarget = ThisWorkbook.ContentTypeProperties("Target group").Value
End If
If TypeName(ThisWorkbook.ContentTypeProperties("Document type").Value) = "String()" Then
If UBound(ThisWorkbook.ContentTypeProperties("Document type").Value) >= 0 Then
strType = ThisWorkbook.ContentTypeProperties("Document type").Value(0)
End If
ElseIf TypeName(ThisWorkbook.ContentTypeProperties("Document type").Value) = "String" Then
strType = ThisWorkbook.ContentTypeProperties("Document type").Value
End If
If strTitle <> "" Then strTitle = " " & strTitle
If strLocation <> "" Then strLocation = " " & strLocation
If strTarget <> "" Then strTarget = " " & strTarget
If strType <> "" Then strType = " " & strType
With ActiveSheet.PageSetup
' -- schreibe nur rein, falls der Text noch nicht drinsteht.
If InStr(1, .LeftHeader, "Title" & strTitle) = 0 Then
.LeftHeader = Replace(.LeftHeader, "Title", "Title" & strTitle)
End If
If InStr(1, .LeftHeader, "Location" & strLocation) = 0 Then
.LeftHeader = Replace(.LeftHeader, "Location", "Location" & strLocation)
End If
If InStr(1, .LeftHeader, "Target group" & strTarget) = 0 Then
.LeftHeader = Replace(.LeftHeader, "Target group", "Target group" & strTarget)
End If
If InStr(1, .LeftHeader, "Document type" & strType) = 0 Then
.LeftHeader = Replace(.LeftHeader, "Document type", "Document type" & strType)
End If
End With
Und dann klappt es auch: