next page - section break / insert file

B

bryan

A 2 prong question:

I have a protected template which has 4 different check boxes. If a check
box is checked, I need to insert a section break/next page AFTER the page.
Once I have inserted the break, I then need to insert a file (document) from
our network drive.
This example, I could insert 4 different files to my template.

Not sure how to code appropriately to add the section break or to insert file.

Any help would be appreciated.

Thanks,
Bryan
 
D

Doug Robbins - Word MVP

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 "Drive:\Path\Filename"
.Protect wdAllowOnlyFormFields, NoReset
End With


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

bryan

Have not tried this code yet but, another question in advance.
Which would be best.
To do this an an exit macro from each checkbox or ?

Thanks,
Bryan
 
B

bryan

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 towards the bottom 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

thanks,
Bryan
 
D

Doug Robbins - Word MVP

See response to your new thread. It is better to continue in the same
thread than to start a new one when the issue is the same.

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