'#Language "WWB-COM" Option Explicit Sub Main Dim doc As Document Dim DataRow As Integer 'Row index in data array Dim CSV_File As String Dim FileContent As String Dim DataArray As Variant Dim RowArray As Variant Dim ColumnIndex As Integer Dim AllTopics As Range Dim CentralTopic As Topic Dim CurrentTopic As Topic Dim ActiveTopic As Topic Dim TL As TextLabels Set doc = ActiveDocument 'Central Topic refers to the CSV file to be used CSV_File = "C:\Users\kum4wee\Syntegon\PANL_MSA - Documents\SVX\Phantom structuur\" & ActiveDocument.CentralTopic.Text & ".csv" Open CSV_File For Input As #1 FileContent = Input$(LOF(1), 1) Close #1 DataArray = Split(FileContent, vbCrLf) Set CentralTopic = ActiveDocument.CentralTopic For DataRow = LBound(DataArray) To UBound(DataArray)-1 'First row is skipped and the -1 is to avoid last row being used twice) Set AllTopics = doc.Range(mmRangeAllTopics) RowArray = Split(DataArray(DataRow), ";") ' Assuming columns are separated by; For ColumnIndex = LBound(RowArray) To UBound(RowArray) Select Case ColumnIndex 'All cases refer to the column number in the data file Case 2 Dim Identnummer As String Identnummer = RowArray(ColumnIndex) Case 4 Dim Parent As String Parent = RowArray(ColumnIndex) Case 8 Dim Phantom As String Phantom = RowArray(ColumnIndex) Case 10 Dim Omschrijving As String Omschrijving = RowArray(ColumnIndex) Case 16 Dim Supplier As String Supplier = RowArray(ColumnIndex) End Select Next ColumnIndex For Each CurrentTopic In AllTopics If Left(CurrentTopic.Text,13) = Parent Then 'Basistekst toevoegen CurrentTopic.AddNewTopic (Identnummer & vbNewLine & Omschrijving ).SelectOnly Set ActiveTopic = ActiveDocument.Selection(1) 'Select the just added topic Set TL = ActiveTopic.TextLabels 'TL is group met textlabels If Phantom = "x" Then TL.AddTextLabel "Phantom" End If If Supplier = "E" Then TL.AddTextLabel "E" End If If Supplier = "F" Then TL.AddTextLabel "F" End If End If Next CurrentTopic Next DataRow End Sub