bstephens
09-05-2010, 11:55 PM
I am trying to create a macro that will create a legal "exhibit" or "schedule".
Basically the macro needs to do the following:
1) Insert a non-linked section break at the current selection
2) Apply a Document Building Block called "Exhibit Header" to the header of the newly created section
3) Apply a Document Building Block called "Exhibit Footer" to the footer of the newly created section
4) Adjust the page numbering of the newly created section so that it is page number 1.
I have the following as a start:
Sub CreateDocumentExhibit()
Dim i As Long
Dim j As Long
Dim oDoc As Word.Document
Dim myRng As Word.Range
Set oDoc = ActiveDocument
Dim oRng As Range
Selection.InsertBreak Type:=wdSectionBreakNextPage
'Get the index number of the added section
i = oDoc.Range(0, Selection.Sections(1).Range.End).Sections.Count
With oDoc.Sections(i)
For j = 1 To 3
.Headers(j).LinkToPrevious = False
.Footers(j).LinkToPrevious = False
Next j
End With
'Note: j provides the constant value to unlink the primary page
'(and the first/even page [if exists]) header/footer in the new section
Application.Templates( _
"C:\Users\bts2000\AppData\Roaming\Microsoft\Document Building Blocks\1033\14\Building Blocks.dotx" _
).BuildingBlockEntries("Exhibit").Insert Where:=Selection.Range, RichText _
:=True
Application.Templates( _
"C:\Users\bts2000\AppData\Roaming\Microsoft\Document Building Blocks\1033\14\Building Blocks.dotx" _
).BuildingBlockEntries("Footer (Exhibit)").Insert Where:=Selection.Range, _
RichText:=True
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
but it obviously doesnt apply the building blocks to the header or footer, can't figure out how to apply the building blocks in the right place.
Appreciate guidance on this.
BTW: planning on releasing a free word add-in for lawyers and legal professionals using all the useful information I have learned and gathered here at www.lawyerword.com (http://www.lawyerword.com). I almost have it ready.
Basically the macro needs to do the following:
1) Insert a non-linked section break at the current selection
2) Apply a Document Building Block called "Exhibit Header" to the header of the newly created section
3) Apply a Document Building Block called "Exhibit Footer" to the footer of the newly created section
4) Adjust the page numbering of the newly created section so that it is page number 1.
I have the following as a start:
Sub CreateDocumentExhibit()
Dim i As Long
Dim j As Long
Dim oDoc As Word.Document
Dim myRng As Word.Range
Set oDoc = ActiveDocument
Dim oRng As Range
Selection.InsertBreak Type:=wdSectionBreakNextPage
'Get the index number of the added section
i = oDoc.Range(0, Selection.Sections(1).Range.End).Sections.Count
With oDoc.Sections(i)
For j = 1 To 3
.Headers(j).LinkToPrevious = False
.Footers(j).LinkToPrevious = False
Next j
End With
'Note: j provides the constant value to unlink the primary page
'(and the first/even page [if exists]) header/footer in the new section
Application.Templates( _
"C:\Users\bts2000\AppData\Roaming\Microsoft\Document Building Blocks\1033\14\Building Blocks.dotx" _
).BuildingBlockEntries("Exhibit").Insert Where:=Selection.Range, RichText _
:=True
Application.Templates( _
"C:\Users\bts2000\AppData\Roaming\Microsoft\Document Building Blocks\1033\14\Building Blocks.dotx" _
).BuildingBlockEntries("Footer (Exhibit)").Insert Where:=Selection.Range, _
RichText:=True
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
but it obviously doesnt apply the building blocks to the header or footer, can't figure out how to apply the building blocks in the right place.
Appreciate guidance on this.
BTW: planning on releasing a free word add-in for lawyers and legal professionals using all the useful information I have learned and gathered here at www.lawyerword.com (http://www.lawyerword.com). I almost have it ready.