Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

So I created a file in excell where

Status
Not open for further replies.

rohman

Programmer
Nov 2, 2003
10
US
So I created a file in excell where I have different rows with different items. In the column next to each Item I write yes or no to. Then I want vb script to make a new document in word, and for every yes insert a certain doc file into the new word document.

So far this is what I have:


Sub createDocNew()
Dim appWord As Word.Application
Dim oWord As Word.Application

Dim currDoc As Word.Document

Dim currDataSheet As Worksheet
Dim addressee As String

Set currDataSheet = ActiveSheet
Set appWord = CreateObject("Word.Application")
appWord.Visible = True
Set currDoc = appWord.Documents.Add()

but I don't know how to use epression.inserfile(filename) command. It keeps giving me an error.

End Sub

 
Hi rohman
From a purely VBA point of view this will insert the text from a document at the current cursor position by using the INCLUDETEXT form field.

Code:
Selection.InsertFile "C:\My Documents\Report1.doc", link:=True

However I'm not a VB programmer and no expert in Word VBA either! I've included an extract from the help file for the InsertFile method to see if that helps you.

I don't freqent this forum but it might help if you still have problems to include details of the error you get. It may also be worth posting on the VBA forum too.

I'm a bit vague on this, but I assume all the relevant references are in place.

Help file extract
Inserts all or part of the specified file.

Syntax

expression.InsertFile(FileName, Range, ConfirmConversions, Link, Attachment)

expression Required. An expression that returns a Range or Selection object.

FileName Required String. The path and file name of the file to be inserted. If you don't specify a path, Word assumes the file is in the current folder.

Range Optional Variant. If the specified file is a Word document, this parameter refers to a bookmark. If the file is another type (for example, a Microsoft Excel worksheet), this parameter refers to a named range or a cell range (for example, R1C1:R3C4).

ConfirmConversions Optional Variant. True to have Word prompt you to confirm conversion when inserting files in formats other than the Word Document format.

Link Optional Variant. True to insert the file by using an INCLUDETEXT field.

Attachment Optional Variant. True to insert the file as an attachment to an e-mail message.


Good Luck!
;-)

If a man says something and there are no women there to hear him, is he still wrong? [ponder]
The faqs ma'am, just the faqs. Get the best from these forums : faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top