Variable Storing a Document

S

Steve C

I wish to use a variable to identify and insert an existing Word document
(7A.doc) into another. 7A.doc is stored in the location G:\Sample. If my
variable is called Category and stores the value "7A.doc", I am experiencing
a "Run-time error 5174 File could not be found" when I use it as follows:

Selection.InsertFile FileName:="G:\Sample\Category", Range:="",
ConfirmConversions:=False, Link:=False, Attachment:=False

What am I doing wrong? Thanks!

Steve C
 
C

Chuck Henrich

FileName:="G:\Sample\Category" means you want to insert a file named
"Category" in the G:\Sample directory.

Your variable "Category" would need to be a string (because the FileName
parameter is a string, so you'd need to declare it properly:

Dim Category as String
Category = "G:\Sample\7A.doc"

Then you'd use it as follows:

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

(note: no quotes around Category).
 
S

Steve C

Thanks for the help, Chuck!

Chuck Henrich said:
FileName:="G:\Sample\Category" means you want to insert a file named
"Category" in the G:\Sample directory.

Your variable "Category" would need to be a string (because the FileName
parameter is a string, so you'd need to declare it properly:

Dim Category as String
Category = "G:\Sample\7A.doc"

Then you'd use it as follows:

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

(note: no quotes around Category).
 

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