Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Command Line. How to tell to XL : If the xls file exist : Open it, if it does not exist : Create it.

Hello,

When I start XL in command line.
How to tell to XL :
If the xls file exist : Open it, if it does not exist : Create it.

Thanks.

Tintin92

  #2   Report Post  
Posted to microsoft.public.excel.programming
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)

  #3   Report Post  
Posted to microsoft.public.excel.programming
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.

Sorry, I have been using VBA for too long. You do not need a sub open
statement and end statement with vb script. Here is what you put in
the file:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Command Line. How to tell to XL : If the xls file exist : Open it, if it does not exist : Create it.

Hello Kletcho,

Seen interesting, maybe it's the way to go.
Thanks.

Tintin92

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
What's command for find sheets exist in workbooks? Jennifer Excel Worksheet Functions 3 December 14th 06 02:16 PM
password to open Excel file option does not exist SabrinaN Excel Worksheet Functions 4 January 23rd 06 02:55 AM
Create Folder If It Doesn't Exist Neutron1871 Excel Programming 4 May 6th 05 01:42 AM
Save to directory and create if not exist Rob Excel Programming 8 January 29th 05 05:39 PM
How to: check if folder exist, if not, create escorido[_2_] Excel Programming 2 July 9th 04 01:28 PM


All times are GMT +1. The time now is 08:33 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"