VBS Script to open Excel wait for it and close it


I would like to open Excel (on the first use so it will take some sekonds to start up and install)
and after the installation I would like to close it...

I know i can use the "Run Method",
           Set WshShell = WScript.CreateObject("WScript.Shell")
           Return = WshShell.Run("excel.exe " & WScript.ScriptFullName, 1, true)
 but if i use this line excel stays open and the code waits until i close excel

I also get problems by closing the excel.exe using this code:
WshShell.Run("excel.exe")
WScript.Sleep 10000
WshShell.Quit("excel.exe")
HelpdeskJBCAsked:
Who is Participating?

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

x
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.

curtiswongCommented:
Dim objExcel
Set objExcel = CreateObject("Excel.Application")
Set objwb = objExcel.Workbooks.Add
Set objws = objwb.Worksheets(1)
objExcel.Visible = True
'do something
WScript.Sleep 1000
objExcel.Quit
HelpdeskJBCAuthor Commented:
Thanks it works, but with your solution the excel don't creates the directory:
%appdata%\Microsoft\Excel\   ! Why?!

when i start the excel with WshShell.Run("excel.exe") it works
( I need this Folder, and the startup of excel are there any other solutions?

and could it be that the excel.application don't suports the .busy function?
With CreateObject("Excel.Application")
        .Visible = True
                Do While .Busy
            WScript.Sleep 1000
        Loop
        .Quit
      End With

with the Internet Explorer this code workes fine...

curtiswongCommented:
I dont have your said folder in my pc even I am using Excel 2007.
However the following code could create the said folder
Dim objExcel, objShell, objFSO
Dim appdataExcel
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
appdataExcel = objShell.ExpandEnvironmentStrings("%APPDATA%") & "\Microsoft\Excel\"
objFSO.CreateFolder appdataExcel
Set objExcel = CreateObject("Excel.Application")
Set objwb = objExcel.Workbooks.Add
Set objws = objwb.Worksheets(1)
objExcel.Visible = True
'do something
WScript.Sleep 1000
objExcel.Quit
As far as I know, Excel.Application does not support "Busy" property, but "Ready" may be the property you need. See the followinig link or google it for details.
http://msdn.microsoft.com/en-us/library/aa176151(office.11).aspx 

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
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
VB Script

From novice to tech pro — start learning today.