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
(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