Een familie van Microsoft-tekstverwerkingssoftware voor het maken van webinhoud, e-mails en afgedrukte documenten.
Sabine,
Onderstaande code geeft de eerste 10 eigenschappen van elk gebruikt(?) opmaakprofiel.
Voor twee eigenschappen heb ik aparte functies geschreven om leesbaar resultaat te krijgen.
Voor de laatste 2 (kleur en onderstrepingsstijl) zal dat ook nog moeten.
Aangenomen dat je een Excelbestand hebt met de eerste drie kolommen zoals je hierboven hebt aangegeven: MapStijlen.xls kom ik tot het volgende:
Sub StijlenRubriceren()
Dim sty As Style
Dim XlApp As New Excel.Application
Dim wkb As Excel.Workbook
Dim sh As Excel.Worksheet
Dim kol As Long
Dim var() As Variant
On Error Resume Next
Set wkb = XlApp.Workbooks.Open("D:\Data\Discussieforum\MapStijlen.xls")
Set sh = wkb.Sheets("Blad1")
kol = 0
ReDim var(30, 0)
For Each sty In ActiveDocument.Styles
With sty
If .InUse Then
var(0, kol) = .NameLocal
var(1, kol) = .Type
var(2, kol) = .BaseStyle
If .BaseStyle = "" Then var(2, kol) = "(geen)"
var(3, kol) = .NextParagraphStyle
If Err > 0 Then
Err = 0
var(3, kol) = "n.v.t."
End If
var(4, kol) = fctUpdate(sty)
With .Font
var(5, kol) = .Name
var(6, kol) = fctFontStyle(sty)
var(7, kol) = .Size
var(8, kol) = .Color
var(9, kol) = .Underline
kol = kol + 1
ReDim Preserve var(30, kol)
End With
End If
End With
Next
XlApp.Visible = True
sh.Range(sh.Cells(1, 4), sh.Cells(31, kol + 3)) = var
End Sub
Function fctUpdate(sty As Style)
Dim strResult As String
On Error Resume Next
Select Case sty.AutomaticallyUpdate
Case True
strResult = "ja"
Case False
strResult = "nee"
End Select
If Err > 0 Then
Err = 0
strResult = "n.v.t."
End If
fctUpdate = strResult
End Function
Function fctFontStyle(sty As Style) As String
Dim strResult As String
If sty.Font.Bold And sty.Font.Italic Then
strResult = "Vet-Cursief"
ElseIf sty.Font.Bold Then
strResult = "Vet"
ElseIf sty.Font.Italic Then
strResult = "Cursief"
Else
strResult = "Standaard"
End If
fctFontStyle = strResult
End Function
de code plaats je in een algemene module van een document;
er moet in VBA een verwijzing worden gemaakt naar de Excel-bibliotheek
de procedure "StijlenRubriceren" is de uit te voeren macro
voor de overige (21) kenmerken moeten een aantal regels (en wellicht extra functies) worden toegevoegd
Hopelijk kun je hier iets mee.
Jan
P.S. de map-verwijzing in deze regel moet uiteraard worden aangepast:
Set wkb = XlApp.Workbooks.Open("D:\Data\Discussieforum\MapStijlen.xls")