Insert document in section

G

GvB

Hi,

I'm trying to create a macro that is going to insert a document per
section. I have allready created a standard macro in Office 2000 like:

Selection.InsertFile FileName:="test.doc", Range:= _
"", ConfirmConversions:=False, Link:=False, Attachment:=False

This inserts the document in the selected section.
In my case I have created a document with 10 sections. Each section is
using a differend document that I want to insert.

Any advice would be appreciated.

Regards,
Giel
 
S

Stefan Blom

You will have to access each section, replacing its contents with the
inserted document.

You can iterate the sections (in a For loop, for example), if you can easily
access Assuming that the document names are "test1", "test2"
etc. this wouldn't be so difficult.


Sub tryout()
Dim s As Section
Dim r As Range
For Each s In ActiveDocument.Sections
Set r = s.Range
r.End = r.End - 1

r.InsertFile Link:=False, _
FileName:="c:\\documents and settings\\sbm01004\\desktop\\tryout.doc"

Next s
End Sub

--
Stefan Blom
Microsoft Word MVP


in message
news:059a71d6-d817-4f9e-9384-ce36b2f879bf@d70g2000hsb.googlegroups.com...
 
S

Stefan Blom

Sorry about the somewhat confusing message (posted by mistake)...

My point is that if you want to iterate sections, you will have to name the
files test1.doc, test2.doc or something like that, so that you can easily
insert them via a For...Next loop. If you don't have names like that, you
will have to deal with each section separately. For example:

Sub Test()

Dim r As Range

'First section, first doc to insert:
Set r = ActiveDocument.Sections(1).Range.Duplicate
r.End = r.End - 1
r.InsertFile Link:=False, _
FileName:="c:\\documents and settings\\sbm01004\\desktop\\tryout.doc"

'Second section, second doc to insert:
Set r = ActiveDocument.Sections(2).Range.Duplicate
r.End = r.End - 1
r.InsertFile Link:=False, _
FileName:="c:\\documents and settings\\sbm01004\\desktop\\test.doc"

'[and so on]

End Sub

The simple loop in my previous message inserts the same document in all
sections.
 
G

GvB

Hi Stefan,

It's working fine as you suggested (per section). I'm not responsibble
for the filenames people give.

Thank you

Giel
 

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