View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected] kletcho@gmail.com is offline
external usenet poster
 
Posts: 11
Default Command Line. How to tell to XL : If the xls file exist : Open it, if it does not exist : Create it.

If you are trying to control excel from outside of excel I would
suggest using a VB Script instead of command line. It allows you to
create an excel object and control it with normal VB code. You could
also use the File System Object to check for the file.

Sub CheckForFile

Dim objXL
Dim fso
Dim strFile

Set objXL = CreateObject("Excel.Application")
Set fso = CreateObject("Scripting.FileSystemObject")

strFile = InputBox("Address and file name")
If fileSystem.FileExists(strFile) Then
objXL.Workbooks.Open("c:\excel\MySpreadsheet.xls")
Else
objXL.Workbooks.Add()
End if

End Sub

Put this into a notepad or word pad and save as YourName.vbs. Then if
you open the file it will run the code.

(The code is untested)