Share this Page URL

The Document Object > The Document Object - Pg. 431

If itm.Class = olContact Then If itm.FullName <> "" _ And itm.CompanyName <> "" And itm.BusinessAddress <> "" Then Debug.Print "Processing " & itm.FullName & " label" With Selection .TypeText Text:=itm.FullName .TypeParagraph .TypeText Text:=itm.CompanyName .TypeParagraph .TypeText Text:=itm.BusinessAddress .TypeParagraph .MoveRight Unit:=wdCell .MoveRight Unit:=wdCell End With End If End If Next itm ErrorHandlerExit: Exit Sub ErrorHandler: MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description Resume ErrorHandlerExit End Sub Example 18-36 shows the use of the Document_Close event, which runs whenever a document is closed. This example increments the value of a document property named InvoiceNumber by 1. Example 18-36. Using a Document_Close Event Private Sub Document_Close( ) 'Written by Helen Feddema 9/30/99 'Last modified 3-26-2000 On Error GoTo ErrorHandler Dim prps As DocumentProperties Dim lngInvoiceNumber As Long 'Store incremented invoice number in template doc property If ActiveDocument.Type = wdTypeDocument Then Set prps = ActiveDocument.AttachedTemplate.CustomDocumentProperties lngInvoiceNumber = prps.Item("InvoiceNumber") + 1 prps.Item("InvoiceNumber") = lngInvoiceNumber ActiveDocument.AttachedTemplate.Save End If ErrorHandlerExit: Exit Sub Working with VBA The Word Object Model | 431