1: ' Avvia l'applicazione Word
2: Dim oWORD As New Word.Application
3: ' Recupera il documento
4: Dim oDOC As Word.Document = oWORD.Documents.Open("c:\temp\MyWordDocument.doc")
5: ' Aggiorna le custom properties
6: For iProp As Integer = 1 To oDOC.CustomDocumentProperties.Count
7: If oDOC.CustomDocumentProperties(iProp).Name = "MyProperty" Then
8: oDOC.CustomDocumentProperties(iProp).Value = "MyValue"
9: Exit For
10: End If
11: Next
12: ' Aggiorna il contenuto del documento
13: oDOC.Fields.Update()
14: ' Aggiorna header e footer
15: oDOC.ActiveWindow.View.Type = Word.WdViewType.wdPrintView
16: oDOC.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader
17: oDOC.ActiveWindow.Selection.WholeStory()
18: oDOC.ActiveWindow.Selection.Fields.Update()
19: oDOC.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekCurrentPageFooter
20: oDOC.ActiveWindow.Selection.WholeStory()
21: oDOC.ActiveWindow.Selection.Fields.Update()
22: ' Chiude salvando il documento
23: oDOC.ActiveWindow.Document.Close(True)
24: ' Chiude l'applicazione Word
25: oWORD.Quit(False)