web 2.0


Adding a serial number to a Word document

This tip shows how to add a serial number to a Word document using VBA. The number is updated everytime the file is opened...

Private Sub Document_Open()
  Set myCell = ThisDocument.Tables(1).Cell(Row:=1, Column:=1)
  nSerial = Left(
myCell.Range.Text, Len(myCell.Range.Text) - 2)
  If nSerial = "" Then nSerial = 0
  ThisDocument.Tables(1).Cell(Row:=1, Column:=1).Range = nSerial + 1
  ThisDocument.Save
End Sub

Tags: , ,

Microsoft Word | Microsoft Word - VBA