Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2006

Tip: Looking for answers? Try searching our database.

Insert word document depending on user form response.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Colm - 09 May 2006 14:47 GMT
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?
Helmut Weber - 09 May 2006 16:01 GMT
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?

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Colm - 09 May 2006 16:13 GMT
thanks Helmut

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

colm

> Hi Colm,
>
[quoted text clipped - 3 lines]
>
> Or is there another problem?
Colm - 09 May 2006 17:04 GMT
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

> thanks Helmut
>
[quoted text clipped - 9 lines]
> >
> > Or is there another problem?
Helmut Weber - 09 May 2006 17:44 GMT
Hi Colm,

what is  "insertbrokerins"?

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Colm - 10 May 2006 08:50 GMT
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

> Hi Colm,
>
> what is  "insertbrokerins"?
Helmut Weber - 10 May 2006 13:06 GMT
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.

Signature

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000

Helmut Weber - 10 May 2006 16:18 GMT
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.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.