473,915 Members | 3,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Running Excel macro from access - code error

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.xl s"
strMacro = "DIP_CTR"
Set xls = CreateObject("E xcel.Applicatio n")
Set xlWB = xls.workbooks.O pen("G:\Hris\Ra chel\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.strmac ro even tho
the excel macro has run.

Any ideas would be greatly appreciated!

Flick. x

Nov 13 '05 #1
6 9869
<ge*********@ho tmail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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.xl s"
strMacro = "DIP_CTR"
Set xls = CreateObject("E xcel.Applicatio n")
Set xlWB = xls.workbooks.O pen("G:\Hris\Ra chel\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.strmac ro even tho
the excel macro has run.

Any ideas would be greatly appreciated!

Flick. x

Nov 13 '05 #2
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*********@ho tmail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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.xl s"
strMacro = "DIP_CTR"
Set xls = CreateObject("E xcel.Applicatio n")
Set xlWB = xls.workbooks.O pen("G:\Hris\Ra chel\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.strmac ro even tho
the excel macro has run.

Any ideas would be greatly appreciated!

Flick. x
Nov 13 '05 #3
Excel 2000 and Access 2000.

Many Thanks

Nov 13 '05 #4
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
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...@hot mail.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
Thank you.

Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
24219
by: Carl | last post by:
Please can anyone tell me how I can create a macro to save the results of a query as an excel file? The query is called Student List and I would like to save it to "My Documents". We have had some problems with our database crashing. We would therefore like another way to have access to basic student data and thought we automatically save the results of this query when we close Access. Any suggestions on how we could do this would be...
2
7664
by: geronimo_me | last post by:
Hi, I have the following code in an access module: Sub Run_Excel_Macro() Dim xls, xlWB As Object Dim strFile, strMacro As String
3
7569
by: bwhite | last post by:
I have a temp table with one row of data that I need to export into Excel. I created the export to create the xls file as follows ... Dim FileName FileName = !! DoCmd.SetWarnings False DoCmd.OpenQuery "qry_delete FCL" DoCmd.OpenQuery "qry_temp FCL"
14
5812
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the SQL DATABASE, probably by the click of a button. Is this possible? & what is the BEST APPROACH for doing this? & also if any links are there do tell those to me too coz I have no idea how to go about doing it.
1
1142
by: Dennis Benjamin | last post by:
Hi All Hope this isn't a FAQ - I've looked for several hours and can't find an answer. I've written my first VB.NET app, a ~20 line console application that opens up an Excel document, compares the number of the last line to the number stored in a text document, and if they're different sends an email ..It's just a tool to alert me when someone has added a request to our log. I wrote it as a standalone app because of the ungodly mess...
10
8225
by: Steve | last post by:
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains custom functions. I believe I need to use COM interop to allow VBA code in Excel 2002 to access it. I've studied everything I can find on COM Interop and .NET. I've also tried many of the 'Walkthroughs' on the MSDN site relating to COM add-ins, .NET and Office XP but am unable to get even these working in Excel 2002 or Word 2002. I've installed the Office XP...
7
6059
by: farhaaad | last post by:
Hi everybody, I just wanted to know if i can make a form in excel (the same as access forms), so when i enter data in excel form it goes to a table in access ? I mean when i enter a value in a cell linked to access table, it goes to table and when i enter another value in the same cell the value goes to the next record. I thank you people in advance!
16
5204
by: Phil Stanton | last post by:
I have a form with a button which is supposed to open an Excel file (With lots of Macros /VBA) in it. The Excel file gets it's data from the Access program Here is the code Private Sub Storage_Click() On Error GoTo Err_Storage_Click
2
5717
by: Cele Balser | last post by:
Hello, This can't be that hard! Could someone give me the code to run a macro in my Personal.xls from my Access module? I have created a query in Access, exported it to a network drive, I can open it, but now need to format it. This is what I have, it works fine to open the Personal.xls but not run the Format_TerrListing macro. (Previous code here......) Dim oXL As Object Dim oExcel As Object Dim sFullPath As String Dim...
0
9883
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
11069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9734
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8102
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5944
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4779
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4346
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.