Open excel spreadsheet from command line

Is there a way to hide the Excel spreadsheet from the command line. I am trying to execute a macro against a spreadsheet from the command line and do not want the spreadsheet to be visible.

Is this possible?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Check excel /e
Though I don't know how to run the macro with that - still read here
Steve KnightIT ConsultancyCommented:
Can you put the macro in the worksheet_open, i.e. something like this ...
Alt F11 to go to VBA editor

Private Sub Workbook_Open()
Application.Visible = False

MsgBox "blah blah"

End Sub

That will hide the window, show a message box (you could run your macro here) and then quit.

You could also start it minimized from cmd prompt with

START /MIN "" "something.xls"
Please don't post duplicate questions. This is a duplicate of http:Q_27492005.html

Since the above mentioned is not really a Java question and dragon-it seems to be on the case here, you should close the earlier one
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

waht kind of macro do you want to execute in your speradsheet without shoowing it?
Maybe it is simpler to run this macro in java code wfrom which you are calling it?
illfusion82Author Commented:
The macro formats a spreadsheet into a pivot table. I need this macro to run against the spreadsheet when no one is logged on to the computer. I have tried this without hiding the excel spreadsheet and it does not work. The process just hangs and I have to terminate it. I know this can be done in vbscript with the below code. But how would I achieve this with Java code?

Option Explicit

Dim oArgs

set oArgs = wscript.Arguments

Call OpenSpreadSheet( oArgs(0), oArgs(1) )

Sub OpenSpreadSheet( strFilePathCustomRpt, strMacroSheetName )
      'On Error Resume Next
      Dim xlMacro
      Set xlMacro = CreateObject("Excel.application")

      xlMacro.Application.Workbooks.Open strMacroSheetName
      xlMacro.Application.Workbooks.Open strFilePathCustomRpt
      xlMacro.Application.Visible = False "'RetinaPivotMacro.xls'!Retina_Macro"

      xlMacro.DisplayAlerts = False
      xlMacro.workbooks( "RetinaSummRpt.txt" ).SaveAs(strFilePathCustomRpt), 56
      xlMacro.DisplayAlerts = True

      Set xlMacro = Nothing

End Sub
Steve KnightIT ConsultancyCommented:
so why not add code to the sheet that does that on startup as suggested?

You could always do something like check an environment variable, or a file exists that you drop in the java in the worksheet_open event to see if you should open the sheet 'normally' or run the relevant macro?

If not over to the java coders...

>> I know this can be done in vbscript with the below code.

In that case, just use java to Runtime.exec the vb script you posted

(see )
String[] command = {
"vbs.exe", "x.vbs" };
Process p = Runtime.getRuntime().exec(command);

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
illfusion82Author Commented:
dragon-it, I have tried with the worksheet_open event, but it still hangs and I have to terminate the excel.exe process.

CEHJ, your suggestion does work, and that is what I am currently doing, but would like to have Java handle executing the macro.
I can't think of any better way other than by looking into the Open Office UNO API to see if you can get it to run the macro
Steve KnightIT ConsultancyCommented:
Do we know WHY it hangs?  You could soon add exactly the same is in your VBScript to the workbook_open?

Maybe it is asking something silly like "enable macros?" ... does it show at all if yo open it visible?

What about if you try first launching a balnk sheet from your java with just an workbook_open event that makes a msgbox or something.

Then try your actual sheet with the same in...

And see how far that gets.  If that works then we can work on your macro part.

>>Do we know WHY it hangs?

Also do we know how you're doing it when it *does* hang? I'm not sure.

If you're doing it with Runtime.exec and it hangs, then you should read the link i posted carefully and thoroughly, including sub-links
illfusion82Author Commented:
I don't think it is asking to enable macros. Below is an article I found on running the excel macro against the spreadsheet through a scheduled task, which is what I am doing. I may just stick with the calling the vbscript to execute the macro for now, until I can find a better solution -- or this may be the best solution. I will leave this open for two more days to get more input.
Start /mim excel.exe {File path}\{File Name}
Steve KnightIT ConsultancyCommented:
@erobby http:#37281808
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.