PC Review


Reply
Thread Tools Rate Thread

Calling excel-macros from script?

 
 
grz01
Guest
Posts: n/a
 
      3rd May 2005
Hi, need a little help here:

We have a directory with a number of excel-documents in it.
Each excel-document has one or more macros in them, that should be run
in sequence.
(the macros will fetch info from a data-source and save output to
another excel-doc)
So far, this has been done manually by a person each morning,
and I would like to automate this by a script, but I dont have much
experience with Windows-scripting.

Thus, in "meta-code" what we want to put in the script is:

Open Exceldoc1
- Run MacroA
- Run MacroB
Close Exceldoc1
Open Exceldoc2
- Run MacroC
- Run MacroD
Close Exceldoc2
.... etc ...

What is the simplest/easiest way to accomplish this? VBS-script?
And what is the exact syntax to do this please? Any help appreciated.
---------------------------------------------------------- grz01

 
Reply With Quote
 
 
 
 
Andy Wiggins
Guest
Posts: n/a
 
      3rd May 2005
You could do this by creating another Excel workbook that acts as the
"manager" of the process. it could run a VBA procedure that opens each
workbook in turn and runs the appropriate macro(s).

Yes, you could do this from a VBS Script. There is an example script at
http://www.bygsoftware.com/Excel/VBA/vbs_script.htm. It doesn't do precisely
what you require but it could point you in the right direction.

--
Regards
-
Andy Wiggins FCCA
www.BygSoftware.com
Excel, Access and VBA Consultancy


"grz01" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi, need a little help here:
>
> We have a directory with a number of excel-documents in it.
> Each excel-document has one or more macros in them, that should be run
> in sequence.
> (the macros will fetch info from a data-source and save output to
> another excel-doc)
> So far, this has been done manually by a person each morning,
> and I would like to automate this by a script, but I dont have much
> experience with Windows-scripting.
>
> Thus, in "meta-code" what we want to put in the script is:
>
> Open Exceldoc1
> - Run MacroA
> - Run MacroB
> Close Exceldoc1
> Open Exceldoc2
> - Run MacroC
> - Run MacroD
> Close Exceldoc2
> ... etc ...
>
> What is the simplest/easiest way to accomplish this? VBS-script?
> And what is the exact syntax to do this please? Any help appreciated.
> ---------------------------------------------------------- grz01
>



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      3rd May 2005
Here is some example code, untested, but should work.

Unfortunately, running VBScript does not have the debugging facilities VBA
in Excel has.

Dim xlApp

Set xlApp = CreateObject("Excel.application")

xlApp.Workbooks.Open "C:\MyFiles\myDoc1.xls"
xlApp.Run "macroA"
xlApp.Run "macroB"
xlApp.ActiveWindow.Close SaveChanges:=False

xlApp.Workbooks.Open "C:\MyFiles\myDoc2.xls"
xlApp.Run "macroC"
xlApp.Run "macroD"
xlApp.ActiveWindow.Close SaveChanges:=False

'repeat for each workbook/macro

xlApp.Quit
Set xlApp = Nothing



--
HTH

Bob Phillips

"grz01" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi, need a little help here:
>
> We have a directory with a number of excel-documents in it.
> Each excel-document has one or more macros in them, that should be run
> in sequence.
> (the macros will fetch info from a data-source and save output to
> another excel-doc)
> So far, this has been done manually by a person each morning,
> and I would like to automate this by a script, but I dont have much
> experience with Windows-scripting.
>
> Thus, in "meta-code" what we want to put in the script is:
>
> Open Exceldoc1
> - Run MacroA
> - Run MacroB
> Close Exceldoc1
> Open Exceldoc2
> - Run MacroC
> - Run MacroD
> Close Exceldoc2
> ... etc ...
>
> What is the simplest/easiest way to accomplish this? VBS-script?
> And what is the exact syntax to do this please? Any help appreciated.
> ---------------------------------------------------------- grz01
>



 
Reply With Quote
 
Hal
Guest
Posts: n/a
 
      3rd May 2005
VBA Script

Workbooks.Open FileName = "c:\exceldoc1"
Application.Run Range("exceldoc1!macroa")
Application.Run Range("exceldoc1!macrob")
ActiveWorkbook.Close
Workbooks.Open FileName = "c:\exceldoc2"
Application.Run Range("exceldoc1!macroc")
Application.Run Range("exceldoc1!macrod")
ActiveWorkbook.Close
etc

"grz01" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi, need a little help here:
>
> We have a directory with a number of excel-documents in it.
> Each excel-document has one or more macros in them, that should be run
> in sequence.
> (the macros will fetch info from a data-source and save output to
> another excel-doc)
> So far, this has been done manually by a person each morning,
> and I would like to automate this by a script, but I dont have much
> experience with Windows-scripting.
>
> Thus, in "meta-code" what we want to put in the script is:
>
> Open Exceldoc1
> - Run MacroA
> - Run MacroB
> Close Exceldoc1
> Open Exceldoc2
> - Run MacroC
> - Run MacroD
> Close Exceldoc2
> ... etc ...
>
> What is the simplest/easiest way to accomplish this? VBS-script?
> And what is the exact syntax to do this please? Any help appreciated.
> ---------------------------------------------------------- grz01
>



 
Reply With Quote
 
grz01
Guest
Posts: n/a
 
      4th May 2005
Thanks Bob,

Seems like I had to use
xlApp.Workbooks.Close
rather than
xlApp.ActiveWindow.Close
Works perfect now
Thanks!


Bob Phillips wrote:
> Here is some example code, untested, but should work.
>
> Unfortunately, running VBScript does not have the debugging

facilities VBA
> in Excel has.
>
> Dim xlApp
>
> Set xlApp = CreateObject("Excel.application")
>
> xlApp.Workbooks.Open "C:\MyFiles\myDoc1.xls"
> xlApp.Run "macroA"
> xlApp.Run "macroB"
> xlApp.ActiveWindow.Close SaveChanges:=False
>
> xlApp.Workbooks.Open "C:\MyFiles\myDoc2.xls"
> xlApp.Run "macroC"
> xlApp.Run "macroD"
> xlApp.ActiveWindow.Close SaveChanges:=False
>
> 'repeat for each workbook/macro
>
> xlApp.Quit
> Set xlApp = Nothing


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling Embedded Object macros from Excel VBA Seption Microsoft Excel Programming 0 5th Mar 2009 07:16 PM
Calling Excel Macros =?Utf-8?B?ZGVyZWsgbWljaGFlbA==?= Microsoft Access VBA Modules 1 16th Jun 2005 04:21 PM
Calling excel-macros from script? grz01 Microsoft Excel Programming 5 4th May 2005 11:11 PM
Calling Excel 4 Macros From VBA =?Utf-8?B?RWxveQ==?= Microsoft Excel Programming 1 24th Jan 2005 04:43 PM
Calling Excel Macros TommyBoy Microsoft C# .NET 3 13th Aug 2004 10:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:15 PM.