By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,628 Members | 1,175 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,628 IT Pros & Developers. It's quick & easy.

Running Excel macro from access - code error

P: n/a
Hi,

I am trying to run an Excel macro from an Access module, however when I
run the code the macro runs but then I get an error in Access. The
error is: Run-time error "440", Automation error.

My code is:
Sub Run_Excel_Macro()

Dim xls, xlWB As Object
Dim strFile, strMacro As String
strFile = "DIP_CTR.xls"
strMacro = "DIP_CTR"
Set xls = CreateObject("Excel.Application")
Set xlWB = xls.workbooks.Open("G:\Hris\Rachel\DIP STUFF\" &
strFile)
xls.Visible = True

xls.Run strMacro ****this is were the code errors******
Set xls = Nothing
Set xlWB = Nothing

End Sub

The macro runs perfect but my code errors at "xls.run.strmacro even tho
the excel macro has run.

Any ideas would be greatly appreciated!

Flick. x

Nov 13 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
<ge*********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi,

I am trying to run an Excel macro from an Access module, however when I
run the code the macro runs but then I get an error in Access. The
error is: Run-time error "440", Automation error.

My code is:
Sub Run_Excel_Macro()

Dim xls, xlWB As Object
Dim strFile, strMacro As String
I suppose you are not aware that writing
Dim strFile, strMacro As String
is the same as writing
Dim strFile as Variant, strMacro as String

If you want both vars be defined as string you must write
Dim strFile As String, strMacro As String

Bruno

strFile = "DIP_CTR.xls"
strMacro = "DIP_CTR"
Set xls = CreateObject("Excel.Application")
Set xlWB = xls.workbooks.Open("G:\Hris\Rachel\DIP STUFF\" &
strFile)
xls.Visible = True

xls.Run strMacro ****this is were the code errors******
Set xls = Nothing
Set xlWB = Nothing

End Sub

The macro runs perfect but my code errors at "xls.run.strmacro even tho
the excel macro has run.

Any ideas would be greatly appreciated!

Flick. x

Nov 13 '05 #2

P: n/a
I have run your code in Access changing only the strFile and strMacro and it
runs without error. This is with Office 2003. You may want to supply more
information (Access and Excel version, etc.).

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.
<ge*********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi,

I am trying to run an Excel macro from an Access module, however when I
run the code the macro runs but then I get an error in Access. The
error is: Run-time error "440", Automation error.

My code is:
Sub Run_Excel_Macro()

Dim xls, xlWB As Object
Dim strFile, strMacro As String
strFile = "DIP_CTR.xls"
strMacro = "DIP_CTR"
Set xls = CreateObject("Excel.Application")
Set xlWB = xls.workbooks.Open("G:\Hris\Rachel\DIP STUFF\" &
strFile)
xls.Visible = True

xls.Run strMacro ****this is were the code errors******
Set xls = Nothing
Set xlWB = Nothing

End Sub

The macro runs perfect but my code errors at "xls.run.strmacro even tho
the excel macro has run.

Any ideas would be greatly appreciated!

Flick. x
Nov 13 '05 #3

P: n/a
Excel 2000 and Access 2000.

Many Thanks

Nov 13 '05 #4

P: n/a
My macro will run in Excel (xls. macro works fine) however my code in
Access debugs with the same error msg "Run-time error "440", Automation
error." (as soon as macro has finished in xls)

Please help - I relly don't get why the macro runs fine from Access but
then errors in Access

Flick. x

Nov 13 '05 #5

P: n/a
Hi!

In addition to the string declarations, mentioned
by Bruno, the same is true for the object
declarations.

Dim xls, xlWB As Object

Declares xls as variant, and xlwb as object, try:

Dim xls as object, xlWB As Object

I can't find any direct errors, but perhaps the
Excel macro isn't finished at the time it hits
the lines releasing the object variables?
Try using a DoEvents:

xls.Run strMacro
DoEvents
Set xlWB = Nothing
Set xls = Nothing

And try reversing the order of releasing
(workbook first).

I don't know, but perhaps also experiment a little
with were you place the xls.visible line?

If neither of these works, I think I'd consider
doing the whole operation from Access. I e copy all
the code from the macro into Access, prefix all
objects, properties and methods with the appropriate
object variables, and see if that works better.

Roy-Vidar

geronimo...@hotmail.com wrote:
My macro will run in Excel (xls. macro works fine) however my code in
Access debugs with the same error msg "Run-time error "440", Automation error." (as soon as macro has finished in xls)

Please help - I relly don't get why the macro runs fine from Access but then errors in Access

Flick. x


Nov 13 '05 #6

P: n/a
Thank you.

Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.