Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default execute macro from command line

Hello,

I would like to run a macro in a workbook from the command line. The macro
modifies the contents of the workbook. This is so I can automate a task
rather than open the workbook, run macro, and save.

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default execute macro from command line

it's unusual to execute a vba macro from the command line.
how about coding windows shell program that automates the excel?
shell programming uses vbscript(*.vbs) or javascript(*.js)
if you're familiar with vba, you would not have difficulty with that.

plz refer http://msdn2.microsoft.com/en-us/library/aa286544.aspx


--
msn
---------------------------------------------
the best time to plant a tree was twenty years ago.
the second best time, is today - Chinese proverb



"swansong" wrote:

Hello,

I would like to run a macro in a workbook from the command line. The macro
modifies the contents of the workbook. This is so I can automate a task
rather than open the workbook, run macro, and save.

Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default execute macro from command line

I'm not sure that you can do this directly but you can use a vbs file as an
intermediary and that might accomplish what you want.

For the example, I have a macro named "macroA" that is in the workbook
"C:\Test\Bookx.xls". I then use notepad to create a file named
"C:\Test\LaunchMacro.vbs" (the vbs file would not have to be in the same
folder, but you will need to know the path for your command line entry).
The contents of LaunchMacro.vbs are shown between the lines below:

______________________________________

myMacro = WScript.Arguments.Item(0)

Set objXL = CreateObject("Excel.Application")
Set objWkbk = objXL.Workbooks.Open("C:\Test\Bookx.xls")
objXL.Run myMacro

objWkbk.Save
objWkbk.Close
objXL.Quit

_________________________________________

Now, if I launch the vbs file and hand it the name of the macro as the
argument, the workbook will open hidden, run the macro, save changes and
close. The command line in this case would be:

C:\Test\LaunchMacro.vbs "macroA"


Steve




"swansong" wrote in message
...
Hello,

I would like to run a macro in a workbook from the command line. The macro
modifies the contents of the workbook. This is so I can automate a task
rather than open the workbook, run macro, and save.

Thanks!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default execute macro from command line

Whilst I would consider the other replies better, you can start a new
instance of Excel, passing arguments, that are parsed by your WB.
See the earlier thread in this NG "Reading command line parameters in a VBA
program".

NickHK

"swansong" wrote in message
...
Hello,

I would like to run a macro in a workbook from the command line. The macro
modifies the contents of the workbook. This is so I can automate a task
rather than open the workbook, run macro, and save.

Thanks!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default execute macro from command line

Thanks!

Seems to work except the macro is not deleting worksheets. Is this because
there is a prompt that asks if you really want to delete the worksheet? Any
workaround to that?

"Steve Yandl" wrote:

I'm not sure that you can do this directly but you can use a vbs file as an
intermediary and that might accomplish what you want.

For the example, I have a macro named "macroA" that is in the workbook
"C:\Test\Bookx.xls". I then use notepad to create a file named
"C:\Test\LaunchMacro.vbs" (the vbs file would not have to be in the same
folder, but you will need to know the path for your command line entry).
The contents of LaunchMacro.vbs are shown between the lines below:

______________________________________

myMacro = WScript.Arguments.Item(0)

Set objXL = CreateObject("Excel.Application")
Set objWkbk = objXL.Workbooks.Open("C:\Test\Bookx.xls")
objXL.Run myMacro

objWkbk.Save
objWkbk.Close
objXL.Quit

_________________________________________

Now, if I launch the vbs file and hand it the name of the macro as the
argument, the workbook will open hidden, run the macro, save changes and
close. The command line in this case would be:

C:\Test\LaunchMacro.vbs "macroA"


Steve




"swansong" wrote in message
...
Hello,

I would like to run a macro in a workbook from the command line. The macro
modifies the contents of the workbook. This is so I can automate a task
rather than open the workbook, run macro, and save.

Thanks!






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default execute macro from command line

Nevermind! I set

Application.DisplayAlerts = False

At the start of the macro and set to true at the end. Working 100%

"swansong" wrote:

Thanks!

Seems to work except the macro is not deleting worksheets. Is this because
there is a prompt that asks if you really want to delete the worksheet? Any
workaround to that?

"Steve Yandl" wrote:

I'm not sure that you can do this directly but you can use a vbs file as an
intermediary and that might accomplish what you want.

For the example, I have a macro named "macroA" that is in the workbook
"C:\Test\Bookx.xls". I then use notepad to create a file named
"C:\Test\LaunchMacro.vbs" (the vbs file would not have to be in the same
folder, but you will need to know the path for your command line entry).
The contents of LaunchMacro.vbs are shown between the lines below:

______________________________________

myMacro = WScript.Arguments.Item(0)

Set objXL = CreateObject("Excel.Application")
Set objWkbk = objXL.Workbooks.Open("C:\Test\Bookx.xls")
objXL.Run myMacro

objWkbk.Save
objWkbk.Close
objXL.Quit

_________________________________________

Now, if I launch the vbs file and hand it the name of the macro as the
argument, the workbook will open hidden, run the macro, save changes and
close. The command line in this case would be:

C:\Test\LaunchMacro.vbs "macroA"


Steve




"swansong" wrote in message
...
Hello,

I would like to run a macro in a workbook from the command line. The macro
modifies the contents of the workbook. This is so I can automate a task
rather than open the workbook, run macro, and save.

Thanks!




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
Run macro from command line Alan Wilson Excel Programming 5 August 22nd 06 03:30 PM
Execute a macro from command line: possible or not ? Drinkmilk Excel Programming 5 April 24th 06 11:48 AM
Macro won't execute from a Command Button Dick Scheibe[_2_] Excel Programming 8 August 21st 05 12:16 AM
Creating command buttons beside every row to execute each row macro sirriff Excel Programming 3 September 12th 04 03:42 AM
Execute a command line app but i want a string returned. dei Excel Programming 0 October 23rd 03 08:18 AM


All times are GMT +1. The time now is 02:26 PM.

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

About Us

"It's about Microsoft Excel"