|
|
||||||
|
#1
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
Hello Kletcho,
Seen interesting, maybe it's the way to go. Thanks. Tintin92 |
|
|
| Similar Threads | |
| Is there a command to open a file as well as to create the directoryif it is not exist? Hi, The following code would give the following error, if the dir 'xy' does not exist. print() on closed filehandle OUT at ./open.pl line 7. I'm wondering if there is a... |
|
| Create file if does not exist but use if it does I have the following SQL code. How can I put a check in here to see if the file already exists and create it if not but insert the data into it if it does? Thanks for your... |
|
| Open Word document if exist, otherwise create one I've tried the following with limited success. It seems as if there is a timing issue or something that causes it not to work as desired. Using the first example, sometimes... |
|
| Open form btn with filter; create if no record exist??Help?? I have a button on my main form frmOrders with the following in the onclick event: Private Sub btnFreight_Click() On Error GoTo Err_btnFreight_Click Dim stDocName As... |
|
| open file in c / create if file doesn't exist Hi everyone! I have a problem with trying to open a file in C. The following line in my code is suppoed to open a specified file if it exists and create a new one with this... |
|
|
All times are GMT. The time now is 12:10 AM. | Privacy Policy
|