Hi all,
I have an Excel sheet with a long list of data. A short example is shown below:
Section | Title | Item
1 | INTRODUCTION | a
1.1 | title2 | b
1.2 | title3 | c
1.2.1 | title4 | d
1.2.2 | title5 | e
...
I made a VBA macro in Excel that runs through this list and creates a new Word file for each item. The filename of the document is based on the data in the Excel file (section and title). Now I would like to add a custom property to each of the newly created Word files, i.e. the value in the 'item' column. Does anyone of you know how I should do this? Or should it be better if I write a macro in Word that runs through the Excel data to create the word files?
Here is the code I use to generate the word files:
Sub createdocuments()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim i, n As Integer
Dim bestandsnaam As String
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
n = 2
For i = 1 To 5
Set wrdDoc = wrdApp.Documents.Add
bestandsnaam = "P:\test\" & Cells(n, 1).Value & " - " & Cells(n, 2).Value & ".doc"
With wrdDoc
If Dir("bestandsnaam") <> "" Then
Kill bestandsnaam
End If
.SaveAs (bestandsnaam)
.Close ' close the document
End With
n = n + 1
Next
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub
I tried this to add a custom property to the word file but this didn't seem to work:
Documents(bestandsnaam).CustomDocumentProperties("Item").Value = "jj"
Bookmarks