Insert word document depending on user form response.

C

Colm

I have constructed a template for creating a letter, this uses several user
forms to collect data from user to construct the final letter.

On one user form there is a question relating to finance and depending on
the answer one of three other word documents need to be inserted in the
letter at that point.

the word files are in a mapped network drive r:

how do i insert them?
 
H

Helmut Weber

Hi Colm,

if you managed to create several userforms,
you should be able to find "file" in the menu "insert",
record a macro, and adapt it to your needs.

Or is there another problem?

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
C

Colm

thanks Helmut

i think there was just too much forest it was hiding the trees on me :)

colm
 
C

Colm

This hasn't worked correctly see code below and advise where i've gone wrong

Private Sub CommandButton1_Click()
If depositpaid.Value = True Then
ActiveDocument.Bookmarks("finance").Range
..InsertBefore vbCr
Call insertbrokerins


End Sub

the insertion of file broker instalments.doc should be at the bookmark
finance.
but when it runs i get a compile error
 
H

Helmut Weber

Hi Colm,

what is "insertbrokerins"?

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
C

Colm

brokerins is a macro to insert the file code below

Sub insertbrokerins()
'
' insertfile Macro
' Macro recorded 5/9/2006 by Colm O'Brien
'
Selection.InsertFile FileName:="broker installments.doc", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
End Sub
 
H

Helmut Weber

Hi Colm,

With ActiveDocument.Bookmarks("finance")
.Range.InsertBefore vbCr
End With
'---
will not insert a paragraph before the bookmark,
but before the first character in the bookmark. :-(

Try:

Sub test000045()
ActiveDocument.Bookmarks("finance").Select
With Selection
.Collapse direction:=wdCollapseStart
.MoveLeft unit:=wdCharacter
.InsertBefore vbCr
.Collapse direction:=wdCollapseEnd
.InsertFile FileName:="c:\test\test.doc"
End With
End Sub

A solution with range instaed of selection
proofed to be a bit more complicated,
but is certainly doable.

It is assumed, that your bookmark isn't located
at a point in the doc, where .moveleft is impossible.
 
H

Helmut Weber

Hi Colm,

from reading your other postings,
it seems, you wanted to insert a vbCr
_in_ the bookmark.

Ask again, if you can't adapt my code to that.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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