Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Macro Error(??)

Hi. I'm trying to run an excel macro through a VB app and am getting 2 weird errors (one which I managed to fix but am not sure why it was broken in the first place). Here's the little snippet of code causing the problems:

Dim XLapp As Excel.Application
Set XLapp = New Excel.Application
Dim WB As Excel.Workbook
Set WB = XLapp.Workbooks.Open(filepath_here)
XLapp.Run "macro_name", file_i_want_macro_to_act_on

The first weird bug is, the XLapp.Workbooks.Open fails if I give
an absolute filepath. I fixed it by giving a relative path, but I'm not
sure why that is necessary.

The second problem I still cannot resolve is I get an error saying that
a macro with that name could not be found (but there is a macro with
that name). Am I calling the Run method improperly??

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Macro Error(??)

I just wanted to be more explicit since maybe there's more to macro names
than I know (?)

Say within a file named foo.xls, I have a macro named my_macro.
Then I typed the following:

Dim XLapp As Excel.Application
Set XLapp = New Excel.Application
Dim WB As Excel.Workbook
Set WB = XLapp.Workbooks.Open("foo.xls")
XLapp.Run "my_macro", file_i_want_macro_to_act_on

and if it matters, foo.xls has many other macros too but i specifically
want to call my_macro.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Macro Error(??)

Hm, well I managed to fix problem #2 heh. And apparently problem #1
was because I had the absolute path in quotes. As soon as I got
rid of those it started working (although I still think it's strange since
quotes around file path names i thought was syntactically correct..and
sometimes even necessary when the filepath has spaces).

Well, if anyone out there was having the same problem as me, here is how
I fixed it:

Dim XLapp As Excel.Application
Set XLapp = New Excel.Application
Dim WB As Excel.Workbook
Dim WB2 As Excel.Workbook
Set WB = XLapp.Workbooks.Open(foo.xls) ' file that has the macro that i want to execute
Set WB2 = XLapp.Workbooks.Open(file.xls) ' xls file that i want the macro to operate on
XLapp.Run "foo.xls!" & macro_name ' Note the exclamation point after foo.xls

' After everything is over let's clean up
WB.Close False
WB2.Close False
XLapp.Quit
Set WB = Nothing
Set WB2 = Nothing
Set XLapp = Nothing
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
Macro Run-time Error 1004 Application Defined or Object Defined Error Anddmx Excel Programming 6 June 9th 04 03:40 PM
Macro 'Automation error' with ChemOffice Excel macro Stew Excel Programming 0 October 27th 03 08:26 PM


All times are GMT +1. The time now is 01:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"