adding section break with no header and footer added

B

bryan

I have a template which has a header and footer and the abiltiy with checkbox
to add another document which I update with information from our host systems.
This works well except I do not want the footer and header carried forward.
I cannot inset page as when renaming formfields it renames all. With a
section break it will only rename the formfields of that section added.
Here is an example of what I am doing:
Sub IDCard1()
‘ item is vehicle numbers loaded from formfield
For Each Item In array2
strInfo = getinfo(Item)
array3 = Split(strInfo, ",")
strrkst = array3(0)

strIDCard = "W:\Commercial\ MN Vehicle Insurance Identification Card.doc"

Set myDoc = ActiveDocument
myDoc.Unprotect

Set docrange = myDoc.Range

With docrange
.Collapse wdCollapseEnd
.InsertBreak wdSectionBreakNextPage
.Collapse wdCollapseEnd
.InsertFile strIDCard
End With

With myDoc.Sections.Last.Range
For z = 1 To .FormFields.Count
.FormFields(z).Name = "Unit" & Item & z
Next z
End With

myDoc.Protect wdAllowOnlyFormFields, NoReset

strvyr = array3(1)
strmake = array3(2)
strmodl = array3(3)
strvin = array3(4)

Stru = "Unit" & Item & 1
strv = "Unit" & Item & 2

ActiveDocument.FormFields(Stru).Result = strvyr & " " & strmake & " " &
strmodl

Next
End If
End Sub


How can I do this so as to not carry the header and footer with a section
break?


Thanks,
Bryan
 
G

Greg Maxey

Bryan,

I can't duplicate your code, but I think you would need something like this:

Sub AddSectionAndKillLinkToPrevious()
Dim i As Long
Dim j As Long
Dim oDoc As Word.Document
Dim myRng As Word.Range
Set oDoc = ActiveDocument
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
.Headers(j).Range = ""
.Footers(j).LinkToPrevious = False
.Footers(j).Range = ""
Next j
End With
'Note: j provides the constant value to delink the primary page
'(and the first/even page [if exists]) header/footer in the new section
End Sub




I have a template which has a header and footer and the abiltiy with
checkbox to add another document which I update with information from
our host systems. This works well except I do not want the footer and
header carried forward.
I cannot inset page as when renaming formfields it renames all. With a
section break it will only rename the formfields of that section
added.
Here is an example of what I am doing:
Sub IDCard1()
' item is vehicle numbers loaded from formfield
For Each Item In array2
strInfo = getinfo(Item)
array3 = Split(strInfo, ",")
strrkst = array3(0)

strIDCard = "W:\Commercial\ MN Vehicle Insurance Identification
Card.doc"

Set myDoc = ActiveDocument
myDoc.Unprotect

Set docrange = myDoc.Range

With docrange
.Collapse wdCollapseEnd
.InsertBreak wdSectionBreakNextPage
.Collapse wdCollapseEnd
.InsertFile strIDCard
End With

With myDoc.Sections.Last.Range
For z = 1 To .FormFields.Count
.FormFields(z).Name = "Unit" & Item & z
Next z
End With

myDoc.Protect wdAllowOnlyFormFields, NoReset

strvyr = array3(1)
strmake = array3(2)
strmodl = array3(3)
strvin = array3(4)

Stru = "Unit" & Item & 1
strv = "Unit" & Item & 2

ActiveDocument.FormFields(Stru).Result = strvyr & " " & strmake & " "
& strmodl

Next
End If
End Sub


How can I do this so as to not carry the header and footer with a
section break?


Thanks,
Bryan

--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org


Nov 4, 2008. Remember it well. You just might
spend your sunset years telling your children and
your children's children what it was once like in
the United States where men were free.
 
B

bryan

When would I call this macro ?
before adding the document?

Thanks,
Bryan


Greg Maxey said:
Bryan,

I can't duplicate your code, but I think you would need something like this:

Sub AddSectionAndKillLinkToPrevious()
Dim i As Long
Dim j As Long
Dim oDoc As Word.Document
Dim myRng As Word.Range
Set oDoc = ActiveDocument
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
.Headers(j).Range = ""
.Footers(j).LinkToPrevious = False
.Footers(j).Range = ""
Next j
End With
'Note: j provides the constant value to delink the primary page
'(and the first/even page [if exists]) header/footer in the new section
End Sub




I have a template which has a header and footer and the abiltiy with
checkbox to add another document which I update with information from
our host systems. This works well except I do not want the footer and
header carried forward.
I cannot inset page as when renaming formfields it renames all. With a
section break it will only rename the formfields of that section
added.
Here is an example of what I am doing:
Sub IDCard1()
' item is vehicle numbers loaded from formfield
For Each Item In array2
strInfo = getinfo(Item)
array3 = Split(strInfo, ",")
strrkst = array3(0)

strIDCard = "W:\Commercial\ MN Vehicle Insurance Identification
Card.doc"

Set myDoc = ActiveDocument
myDoc.Unprotect

Set docrange = myDoc.Range

With docrange
.Collapse wdCollapseEnd
.InsertBreak wdSectionBreakNextPage
.Collapse wdCollapseEnd
.InsertFile strIDCard
End With

With myDoc.Sections.Last.Range
For z = 1 To .FormFields.Count
.FormFields(z).Name = "Unit" & Item & z
Next z
End With

myDoc.Protect wdAllowOnlyFormFields, NoReset

strvyr = array3(1)
strmake = array3(2)
strmodl = array3(3)
strvin = array3(4)

Stru = "Unit" & Item & 1
strv = "Unit" & Item & 2

ActiveDocument.FormFields(Stru).Result = strvyr & " " & strmake & " "
& strmodl

Next
End If
End Sub


How can I do this so as to not carry the header and footer with a
section break?


Thanks,
Bryan

--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org


Nov 4, 2008. Remember it well. You just might
spend your sunset years telling your children and
your children's children what it was once like in
the United States where men were free.
 

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