Add unique document number to all footers

S

Senad Isanovic

Need to write code that will add unique document number and version no
(basicaly just the string that looks like doc282827-v2) in the footer of the
document. It can be table or bookmark or doc variable or give me any other
suggestion that you have. My documents can have 80 - 90 pages and even more.
They can have several different sections with different footers. If there is
an existing footer in the doc, the content and the layout of the footer
should not be affected by adding a doc number. The documents can have
different first page or not. The doc number should be added in the footer at
every page of the document (no matter of the number of pages or sections).
This is the code I have so long. Many Thanks!



Option Explicit



Sub AddMarkup()

assignBoomarkToTable "DocID_98878-v1"



End Sub



Sub assignBoomarkToTable(strMarkupValue As String)

Dim tblID As Table

Dim rgeFooter As Range, sSec1 As Section

Const strTableName As String = "bkfooter00001"

On Error GoTo errhandler



Set sSec1 = ActiveDocument.Sections.Item(1)



Set rgeFooter =
sSec1.Footers(wdHeaderFooterPrimary).Range.Paragraphs(1).Range

rgeFooter.Collapse wdCollapseStart



'Add a table in that footer and assign bookmark

If rgeFooter.Tables.Count > 0 Then

If ActiveDocument.Bookmarks.Exists(strTableName) Then

ActiveDocument.Bookmarks(strTableName).Range.Tables(1). _

Cell(1, 1).Range.Text = strMarkupValue

Exit Sub

End If

End If

Set tblID = rgeFooter.Tables.Add(rgeFooter, 1, 1)



tblID.Columns(1).Width = InchesToPoints(2)

ActiveDocument.Bookmarks.Add strTableName, tblID.Range



ActiveDocument.Bookmarks(strTableName).Range.Tables(1) _

.Cell(1, 1).Range.Text = strMarkupValue



Set sSec1 = Nothing

Set rgeFooter = Nothing

Set tblID = Nothing



Exit Sub



errhandler:

MsgBox Err.Description, vbInformation



End Sub
 
D

Doug Robbins - Word MVP

You may not find exactly what you are looking for and will have to modify
something to do what you want.

You should start by setting up the template that you use as a basis for the
documents so that it already starts with the number in it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top