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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Not Found Error when Word is NOT Active

Status
Not open for further replies.

hrm03

Programmer
Apr 30, 2003
28
0
0
US
Hello. Up until now I have had no problem with what I am trying to do; which is...use the GetObject function to grab a word template from our server, insert information, print it, then close without saving. I want this all to be done in the background without the user even seeing the Word Application. Now, unless word is open on the computer, I get the error message "File Not Found!". If I have word open, it goes through like a charm. I have no idea what has changed so any ideas here would be a HUGH help! THANKS!
 
Thanks, but can you create an object that already exists? I have these templates setup and I have to use them. So I thought that I had to use GetObject rather than CreateObject. Is that not right? Is there anyway to making the system think that the word application is open and active, without being obvious to the users? Thanks again!
 
It is possible to create multiple occurrences of objects.

But in your case, you are attempting to Set an application Object using GetObject. If the ("OBJECT") is not there, then you have to CreateObject("OBJECT"). It's only there in your application, and it goes away, assuming that you close whatever objects were opened within that application and set the application object to Nothing.

Skip,
Skip@TheOfficeExperts.com
 
I'm sorry, maybe I am not being clear. These templates are out there regardless of my application and what it does; I can access them at any time. Only, when I am running the program, and word is not already open (not the document itself, just the application) I get "Run-Time Error '5174' This File Could Not Be Found". The crazy thing is that if I have word open, not to any particular file, just open, everything works great and I have no error message. Thanks for trying to understand what I am attempting to do.
 
I am writing in VB6 and trying to automate word 2000
 
Skip,
Any more ideas on this one? Thanks!
 
Skip,
The program does what it is supposed to, by opening a template and filling the information, then it is supposed to insert that file, into another template; this is where it goes wrong. This code is what takes the already filled out template and places it into another. On the insert file line is where I get the message.

Sub MergeDoc1(objWdMergeDoc As Word.Document, sDocPath As String, sDocName As String)

Dim BMRange As Range

Set BMRange = objWdMergeDoc.Bookmark("CollectionLetter").Range
BMRange.InsertFile GetObject(sDocPath + sDocName)
objWdMergeDoc.Bookmarks.Add "CollectionLetter", BMRange

End Sub

The DocPath and DocName come through fine and like I said, the strange thing is that it can find the file with no problem if I have an instance of Word running. It only bombs out when it is closed. Thanks for your help.
 
I beileve that this is the form of the GetObject method...
Code:
   Dim doc as Word.Document
   Set doc = GetObject(sPath + fname, "Word.Document")
I was able to set the document object with Word closed.

Hope this helps :)

Skip,
Skip@TheOfficeExperts.com
 
Skip,
Thanks for the tip but when I entered that part in, I have another error message:
"Method 'Insert File' of Object 'Range' Failed!"
Any ideas on that one? Thanks
 
Skip,
FYI: Once I worked through the other one I am still getting the same error messge as before (File not found). Thanks though.
 
Skip,
Upon looking at your code again, I realized that I have done this when first getting the information into these templates. What I am now trying to do, is insert that file. The only way I knew to get that file name inserted (b/c it is variable) was to use the GetObject method hence the code:

BMRange.InsertFile GetObject(sDocPath + sDocName)

If you know of another way for me to insert the file name here, I would like to try that. Thanks.
 
Why are you doing that .Insert? The GetObject is returning a document object as you are using it. You are trying to set a Range object instead of a document object.

If you are getting a file not found message, your path/filename is incorrect.

Look at the concatenated string and be SURE that there is a "\" between the path and filename.

Skip,
Skip@TheOfficeExperts.com
 
I am actually inserting this file into a bookmark in a certain place on another template. That is why I would think I had to use this code (.Insert). I am new to this, obviously, so if there is another (better) way to go about doing this I would be up to try it. And yes, my file names are correct. Thanks.
 
You are not going to insert a document object. You are going to insert a range object.

First set your document object. Then referencing the document object.

Now I'm no Wrod VBA guru, so the way I might choose could more than likely be coded ALOT better. But here goes...
Code:
'get the document
Set doc = GetObject(Path + fName, "Word.Document")
'aRange is the whole document
Set aRange = doc.Range( _
    Start:=doc.Paragraphs(1).Range.Start, _
    End:=doc.Paragraphs(doc.Paragraphs.Count).Range.End)

'append doc to end of whatever
MyTemplateRange.EndOf(Unit:=wdParagraph, Extend:=wdExtend) = aRange
Sumthin' like that, mebe?

Skip,
Skip@TheOfficeExperts.com
 
Thanks, I'll give it a try and let you know what I come up with. Thanks again for your help.
 
Skip,
Sorry. That didn't work either. All new errors showed up plus nothing was reading in correctly. Thanks for your thoughts though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top