Group: microsoft.public.word.vba.general
From: "Doug Robbins - Word MVP"
Date: Thursday, April 10, 2008 2:58 PM
Subject: Re: section add - insert file

If you always want the documents added at the end of the document in a new
section, use:

If ActiveDocument.FormFields("Check2").CheckBox.Value = True Then
Dim myDoc As Document
Dim docrange As Range

Set myDoc = ActiveDocument
With myDoc
.Unprotect
Set docrange = .Range
docrange.Collapse wdCollapseEnd
docrange.InsertBreak wdSectionBreakNextPage
Set docrange = .Range
docrange.Collapse wdCollapseEnd
docrange.InsertFile "u:\temp3.doc"
.Protect wdAllowOnlyFormFields, NoReset
End With
End If


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

"bryan" wrote in message
news:EDAA8F25-032B-4098-B974-D9864C8E0B1D@microsoft.com...
>I have tried this code and it works well if I select one checkbox. If I
> select more than 1, it is not working correctly.
> My template is a letterhead (top and bottom) as are my documents.
> When I check box one, it adds temp2.doc correctly.
> When I check box 2, it adds a blank letterhead after my template page,
> then
> adds
> temp3.doc as a continuation of temp2.doc rather than starting a new page.
> I have in chk2 named myDoc1 and docrange1 but, that did not help
> Here is the code for each check box:
> Sub chk1()
> '
> ' chk1 Macro
> ' Macro created 4/10/2008 by bjsorens
> '
> If ActiveDocument.FormFields("Check1").CheckBox.Value = True Then
> Dim myDoc As Document
> Dim docrange As Range
>
> Set myDoc = ActiveDocument
> With myDoc
> .Unprotect
> Set docrange = Selection.Bookmarks("\Page").Range
> docrange.Collapse wdCollapseEnd
> docrange.InsertBreak wdSectionBreakNextPage
> Set docrange = .Range
> docrange.Collapse wdCollapseEnd
> docrange.InsertFile "u:\temp2.doc"
> .Protect wdAllowOnlyFormFields, NoReset
> End With
> End If
> End Sub
>
> Sub chk2()
> '
> ' chk1 Macro
> ' Macro created 4/10/2008 by bjsorens
> '
> If ActiveDocument.FormFields("Check2").CheckBox.Value = True Then
> Dim myDoc As Document
> Dim docrange As Range
>
> Set myDoc = ActiveDocument
> With myDoc
> .Unprotect
> Set docrange = Selection.Bookmarks("\Page").Range
> docrange.Collapse wdCollapseEnd
> docrange.InsertBreak wdSectionBreakNextPage
> Set docrange = .Range
> docrange.Collapse wdCollapseEnd
> docrange.InsertFile "u:\temp3.doc"
> .Protect wdAllowOnlyFormFields, NoReset
> End With
> End If
> End Sub
>
> Would appreciate any help so that by checking more than 1 box, the next
> file
> (document) added would append after the last.
>
> Thanks,
> Bryan
>