+ Reply to Thread
Results 1 to 4 of 4

Command Line. How to tell to XL : If the xls file exist : Open it, if it does not exist : Create it.

  1. #1
    Tintin92
    Guest

    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. #2

    Re: 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. #3

    Re: 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. #4
    Tintin92
    Guest

    Re: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1