Click to See Complete Forum and Search --> : OFFICE AUTOMATION!!!!


thebernieb
October 8th, 2001, 01:13 PM
Folks,

I've written a fairly simple utility to search a given directory for .DOC files and fill up a list box with the path\filename. After this is done it opens a new word.application object. Then it iterates through the list box, attempts to open each file, deletes the VB Code, attaches a new templates, saves, and then closes the document. Onces all of the documents have been "fixed" then word.application is 'quit'. I've tested it on my machine and it works great, but when I try to run it on the computer it was made for I get errors. It says object variable not set and returns line 8250:

8240 Set objDocument = objWordApp.Documents.Open(strDocFile)

8250 intCodeLineCount = objDocument.VBProject.VBComponents("ThisDocument").CodeModule.CountOfLines

8260 If intCodeLineCount > 0 Then objDocument.VBProject.VBComponents("ThisDocument").CodeModule.DeleteLines 1, intCodeLineCount

**objDocument uses late binding **objWordApp uses early binding

I just don't get it, I didn't jump into any With Blocks and I'm fairly certain the methods I used for the automation are tight. I'm sure it might be hard to help without seeing all of the code, but I didn't want to post too much and bore someone. Is it possible that on a slower machine it takes longer for the document to open and register thereby generating errors because the object is not fully loaded? I'm at a loss and tired of messing with this thing. Please HELP!!!

Thanks,

Bernie

Cakkie
October 8th, 2001, 03:49 PM
First of all, the speed of the PC it runs on has got nothing to do with it. I think you need to look further. Normally, the objDocument must be set, otherwise the error should have happened on the previous line. So I think you must look at the VBProject. Since every word document has one, this shouldn't be the problem. Then we arrive at VBComponents("ThisDocument"), my guess is that the problem is here. I think you might just have encountered a file that doesn't a component called ThisDocument, which is the default. Probably, this has been renamed for one reason or another. Add some errorhandling to the program, which will show you to filename you are currently working on (if you don't display it anywhere). Then open that file in Word, and open the VB Editor. See if there is an object called ThisDocument.

Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook