Using Selection.InsertFile

R

Rick

I have a macro that is executed only after users have already opened a
fairly complex, four-page document. I now want to add VBA code to say:

if var1="Y" then
insert Word document YES.DOC at such-and-such position in
the currently-opened document
elseif if var1="N" then
insert Word document NO.DOC at the same position in
the currently-opened document
end if

I think I use Selection.InsertFile to insert, but I don't know how to
tell Word to open YES.DOC/NO.DOC in the specific location that I want
within the already-opened document. Do I use bookmarks?
Selection.InsertFile seems to insert the doc at the current cursor
position, whereas I may or may not want it there.

Any help would be appreciated. Thanks.
 
D

Doug Robbins - Word MVP on news.microsoft.com

Insert a bookmark named "Target" where you want the document inserted.

Dim DocName As String
Dim Target As Range
If Var1 = "Yes" Then
DocName = "[path]\Yes.doc"
ElseIf Var1 = "No" Then
DocName = "[path]\No.doc"
End If
Set Target = ActiveDocument.Bookmarks("Target").Range
Target.InsertFile DocName


--
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, originally posted via msnews.microsoft.com
 

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