创建Excel对象会导致自动化错误 [英] Creating Excel objects causes Automation Error

查看:119
本文介绍了创建Excel对象会导致自动化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我在Access窗体后面遇到了VB的痛苦。该表单用于

根据表单中输入的详细信息在Excel中创建报表。这个

一直在我的机器上运行没有错误(NT4,Access 2k),但是当我尝试在另一台机器上创建任何东西时,

$ b大多数用户将使用$ b(NT4,Access 2k),我收到一个

自动化错误。


代码的问题在于:

设置objXL =新的Excel.Application


和任何试图访问任何创建的Excel对象的行都将导致

自动化错误。


声明包括:

Dim objXL As Excel.Application

Dim objWkb As Excel.Workbook

Dim objSht作为Excel.Worksheet


和两台机器上VB的引用是:

Access 9.0 Object Library

ActiveX数据对象2.1库

DAO 3.6对象库

Excel 9.0对象库

OLE自动化

ActiveX数据对象Recordset 2.5库


在中断模式下,如此当代码命中任何引用

对象的行时(即。 objXL,objWkb或objSht)它的错误。


我将不胜感激为此提供任何建议!令人沮丧的是,它在一台机器上完美运行,但在另一台机器上却没有,而且在另一台机器上运行得非常好。我很乐意发布更多

的详细信息,如果它们有助于解决这个问题...


提前致谢! Angela

解决方案

嗨再次,


TC - 我绝对可以正常打开Excel,它使用得很好经常

没有问题。


史蒂夫 - 在违规机器上你的线路似乎发生了什么

是这样的:当它命中行集objXL = GetObject(,

" Excel.Application"),它出错并转到错误处理程序。

错误是预期的#429(因为Excel未打开),但是在那时

尝试执行Set objXL = CreateObject(" Excel.Application")in

错误处理程序,再次发生错误。消息是Err#13类型

不匹配。


因此,问题似乎与设置objXL有关。还有其他

的想法吗?


我也试过使用声明Dim objXL作为Object然后使用建议的行使用
。这大部分时间都工作(在

违规机器上),但不能使用CopyfromRecordset动作(以及

其他几个)这对我来说是一个至关重要的动作。


另外,史蒂夫你建议的线路在我的机器上工作得很好,但

不是有问题的机器(与原始问题相同)。

再次感谢,非常感谢您的帮助! Angela
sg******@srs.gov (Steve Tahan)在留言中写道:< ; 56 ************************* @ posting.google.c om> ...

我有一个应用程序打开一个现有的Excel WB(一个模板),其中包含以下代码:我从Helen Feddema的Access Archon文章中刷过:

Dim objXL as Excel.Application

set objXL = GetObject(,Excel.Application)

''如果Excel正在运行,它将使用当前运行的版本。
''如果没有,则会生成错误错误
处理程序处理。

如果err.Number = 429那么
设置objXL = CreateObject(Excel。应用程序)
继续下一页
其他


这对我很有用。

Steve Tahan,ITS Westinghouse Savannah River Co.。



Ange


请尝试以下a b广告电脑。不要设置任何错误处理。究竟是什么

是错误编号&你得到的消息?


dim objXL作为对象

set objXL = createobject(" excel.application")


(如果一直有效,请再试一次,这次dim''ming objXL为

Excel.Application。)


TC


" Ange T" < SM ************* @ yahoo.com>在留言中写道

news:b7 ************************** @ posting.google.c om ...

嗨再次,
TC - 我绝对可以正常打开Excel,它经常使用
没有任何问题。

史蒂夫 - 在违规机器上你的线路似乎发生了什么
是这样的:当它遇到线路设置objXL = GetObject(,
Excel.Application)时,它会出错并转到错误处理程序。
错误是#429正如预期的那样(因为Excel未打开),但是当时尝试在错误处理程序中执行Set objXL = CreateObject(" Excel.Application"),再次发生错误。消息是Err#13类型
不匹配。

因此,问题似乎与设置objXL有关。还有其他的想法吗?

我也试过使用声明Dim objXL作为Object然后
使用建议的行。这大部分时间都适用(在违规机器上),但不能使用CopyfromRecordset动作(以及其他几个动作),这对我来说是一个至关重要的动作。
另外,史蒂夫你建议的线路在我的机器上完美运行,但
不是问题机器(与原始问题相同)。

再次感谢,非常感谢你的帮助! Angela
sg******@srs.gov (Steve Tahan)在留言中写道


新闻:< 56 ************************* @ posting.google.c om> ...

我有一个应用程序打开现有的Excel WB(模板),其中包含以下代码,我从Helen Feddema的Access Archon文章中刷过:

Dim objXL as Excel.Application

设置objXL = GetObject(,Excel.Application)

''如果Excel正在运行,它使用当前运行的版本。
''如果没有,它会生成错误处理错误
处理程序。

Error_Handler

如果err.Number = 429那么
设置objXL = CreateObject(Excel.Application)
继续下一步
其他


这个对我来说效果很好。

Steve Tahan,ITS
Westinghouse Savannah River Co.



Ange,听起来好像你还没有在Tools:References中选择Excel对象库

。尝试在设计视图中打开任何模块,转到

工具:引用,并确保Microsoft Excel 8.0

对象库的条目。被勾选了。 (8.0可能会有所不同,具体取决于您的Excel

版本。)


HTH,

TC

Ange T< sm ************* @ yahoo.com>在消息中写道

新闻:b7 ************************* @ posting.google.co m ... < blockquote class =post_quotes>嗨TC,

当我将objXL作为对象变暗时 - 创建对象时没有错误
使用set objXL = ...

(但是我故意试图避免使用这种方法,因为它不允许我使用copyfromrecordset等功能。)

当我将objXL变暗为Excel.Application时,行#objxl
= ...的错误是错误#13类型不匹配。

期待收到你的回复,Ange。

TC < a@b.c.d>在消息新闻中写道:< 1063774302.471686@teuthos> ...

Ange

尝试下面的坏电脑。不要设置任何错误处理。
究竟是错误编号&你得到的消息是什么?

dim objXL as object
set objXL = createobject(" excel.application")

(如果一致,请再试一次,这个时间dim''ming objXL as
Excel.Application。)

TC



Hi there,

I''m having pain with the VB behind an Access form. The form is used to
create reports in Excel based on the details entered in the form. This
has always worked without error on my machine (NT4, Access 2k),
however as soon as I attempt to create anything on another machine
(NT4, Access 2k) which most users will be working from, I receive an
automation error.

The problem line with the code is:
Set objXL = New Excel.Application

and any line that attempts to access any Excel objects created will
also cause an automation error.

The declarations include:
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet

and the references for the VB on both machines are:
Access 9.0 Object Library
ActiveX Data Objects 2.1 Library
DAO 3.6 Object Library
Excel 9.0 Object Library
OLE Automation
ActiveX Data Objects Recordset 2.5 Library

In break mode, as soon as the code hits any line referencing the
object (ie. either objXL, objWkb or objSht) it errors.

I would appreciate any advice that can be offered on this! It''s so
frustrating that it works perfectly on one machine, but not on another
with a similar configuration. I am more than happy to post more
details if they''d be useful to help solve this...

Thanks in advance! Angela

解决方案

Hi again,

TC - I can definitely open Excel normally, it is used quite regularly
with no problems.

Steve - what seems to happen with your line on the offending machine
is this: When it hits the line set objXL = GetObject(,
"Excel.Application"), it errors and goes to the error handler. The
error is #429 as expected (since Excel is not open), however in then
attempting to execute Set objXL= CreateObject("Excel.Application") in
the error handler, an error occurs again. The message is Err #13 Type
Mismatch.

Thus, again the problem seems to be with setting objXL. Any other
ideas?

I have also tried using the declaration Dim objXL as Object and then
using the lines suggested. This works most of the time (on the
offending machine), however the CopyfromRecordset action (as well as
several others) cannot be used which is a crucial action for me.

Also, Steve the lines you suggested work perfectly on my machine, but
not the problematic machine (same as original problem).
Thanks again, I really appreciate your help! Angela
sg******@srs.gov (Steve Tahan) wrote in message news:<56*************************@posting.google.c om>...

I have an app that opens an existing Excel WB (a template) with the
following code I swiped from Helen Feddema''s Access Archon article:

Dim objXL as Excel.Application

set objXL = GetObject(, "Excel.Application")

'' If Excel is running, it uses the current running version.
'' If not, it generates an error that is dealt with in the error
handler.

Error_Handler

If err.Number = 429 Then
Set objXL= CreateObject("Excel.Application")
Resume Next
Else
...

This works well for me.

Steve Tahan, ITS
Westinghouse Savannah River Co.



Ange

Try the following an the bad pc. Do not set any error handling. What exactly
is the error number & message you get?

dim objXL as object
set objXL = createobject ("excel.application")

(If that works consistently, try again, this time dim''ming objXL as
Excel.Application.)

TC

"Ange T" <sm*************@yahoo.com> wrote in message
news:b7**************************@posting.google.c om...

Hi again,

TC - I can definitely open Excel normally, it is used quite regularly
with no problems.

Steve - what seems to happen with your line on the offending machine
is this: When it hits the line set objXL = GetObject(,
"Excel.Application"), it errors and goes to the error handler. The
error is #429 as expected (since Excel is not open), however in then
attempting to execute Set objXL= CreateObject("Excel.Application") in
the error handler, an error occurs again. The message is Err #13 Type
Mismatch.

Thus, again the problem seems to be with setting objXL. Any other
ideas?

I have also tried using the declaration Dim objXL as Object and then
using the lines suggested. This works most of the time (on the
offending machine), however the CopyfromRecordset action (as well as
several others) cannot be used which is a crucial action for me.

Also, Steve the lines you suggested work perfectly on my machine, but
not the problematic machine (same as original problem).
Thanks again, I really appreciate your help! Angela
sg******@srs.gov (Steve Tahan) wrote in message


news:<56*************************@posting.google.c om>...

I have an app that opens an existing Excel WB (a template) with the
following code I swiped from Helen Feddema''s Access Archon article:

Dim objXL as Excel.Application

set objXL = GetObject(, "Excel.Application")

'' If Excel is running, it uses the current running version.
'' If not, it generates an error that is dealt with in the error
handler.

Error_Handler

If err.Number = 429 Then
Set objXL= CreateObject("Excel.Application")
Resume Next
Else
...

This works well for me.

Steve Tahan, ITS
Westinghouse Savannah River Co.



Ange, it sounds to me as if you have not selected the Excel object library
in Tools:References. Try opening any module in design view, go to
Tools:References, and make sure that the entry for "Microsoft Excel 8.0
Object Library" is ticked. (8.0 might be different, depending on your Excel
version.)

HTH,
TC
Ange T <sm*************@yahoo.com> wrote in message
news:b7*************************@posting.google.co m...

Hi TC,

When I dim objXL as object - there is no error in creating the object
using set objXL = ...

(However I have deliberately tried to avoid using this approach as it
doesn''t allow me to use functions such as copyfromrecordset etc.)

When I dim objXL as Excel.Application, the error at the line set objxl
= ... is error # 13 "Type mismatch".

Looking forward to hearing from you, Ange.
"TC" <a@b.c.d> wrote in message news:<1063774302.471686@teuthos>...

Ange

Try the following an the bad pc. Do not set any error handling. What exactly is the error number & message you get?

dim objXL as object
set objXL = createobject ("excel.application")

(If that works consistently, try again, this time dim''ming objXL as
Excel.Application.)

TC



这篇关于创建Excel对象会导致自动化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆