'After doing:
'Set objExcel = CreateObject("Excel.Application")
'Set abook = objExcel.Workbooks.Open(NameFile)" earlier in the program

'The following line gives me an error at runtime:
Set xlmodule = abook.VBProject.VBComponents.Add(1)

Does anyone have any idea why and how that line could give me an error
57: Device I/O error ???

Re: Device I/O Error when adding a component? by Michael

Michael
Wed Jan 26 18:56:52 CST 2005

wolfing1@yahoo.com wrote:
> 'After doing:
> 'Set objExcel = CreateObject("Excel.Application")
> 'Set abook = objExcel.Workbooks.Open(NameFile)" earlier in the program
>
> 'The following line gives me an error at runtime:
> Set xlmodule = abook.VBProject.VBComponents.Add(1)
>
> Does anyone have any idea why and how that line could give me an error
> 57: Device I/O error ???


When I try something similar (Excel 2003), I get

C:\Scripts\junk.vbs(5, 1) Microsoft Office Excel: Programmatic access to
Visual Basic Project is not trusted

The fix is detailed at:

PRB: Programmatic Access to Office XP VBA Project Is Denied
http://support.microsoft.com/kb/q282830/


--
Michael Harris
Microsoft MVP Scripting



Re: Device I/O Error when adding a component? by wolfing1

wolfing1
Thu Jan 27 13:27:17 CST 2005

Thanks but I think the article only applies for 2003 versions (and
above). In our case we're using Office 2000. The program 99% of the
time runs fine, the problem happens once in a while when several
instances of the program are running simultaneously, although they have
different Excel files open of course


Re: Device I/O Error when adding a component? by Michael

Michael
Thu Jan 27 14:18:25 CST 2005

wolfing1@yahoo.com wrote:
> Thanks but I think the article only applies for 2003 versions (and
> above). In our case we're using Office 2000.

It applies to Office XP (2002) an works for Office 2003 (which I tested on).
In any case, my error was different from yours.


> ... The program 99% of the
> time runs fine, the problem happens once in a while when several
> instances of the program are running simultaneously, although they
> have different Excel files open of course

You never said the problem was intermittent and occurred only when multiple
instance are running. Those kinds of stress bugs are hard to resolve.

If the problem occurs *only* on the call to the ...VBComponents.Add method,
you could try trapping for the error any retrying a reasonable number of
times, calling 'WScript.Sleep 100' within the retry loop. You'll need to
experiment with the number of retries and the length of the sleep...

No guarantee this will solve the problem, but it seems worth a try...

--
Michael Harris
Microsoft.MVP.Scripting


Re: Device I/O Error when adding a component? by wolfing1

wolfing1
Fri Jan 28 08:05:20 CST 2005

guess I can try that thanks, it still bugs me how I could get a device
I/O error when adding a module to the excel object *shrug*