1

I am trying to open an excel sheet with Excel 2003 that has a custom built extension.

I am able to open that specific version of excel which has custom built extension using the file path but I am not able to open a certain file it.

This is what I want to do:

1) Open Excel 2003 with a custom built extension 2) Open a specific file in it 3) Run a macro 4) close

I can not simply open an excel file because it opens it with normal Excel 2003 which does not have the custom built extension to it. Therefore, I have to open the Excel 2003 with the custom built extension and then open the excel file that I want to open.

I know I was kind of all over the place asking the question but if it needs clarification I will explain it more.

bensiu
  • 24,660
  • 56
  • 77
  • 117
  • Post the code you have so far - that should help clarify what you're trying to do. – Tim Williams Oct 29 '12 at 18:05
  • So far I only have a command line in a batch file that opens the excel with custom built extension. Instead of going file->open->picking the file name. It would be helpful if I can automate that and write a code so it opens a certain file in that custom built excel. – user1783633 Oct 31 '12 at 19:29
  • What exactly is your "custom built extension"? Typically you would use a small vbscipt to do this kind out automation, but i'm not sure how it might be affected by whatever your extension is. http://stackoverflow.com/questions/10232150/run-excel-macro-from-outside-excel-using-vbscript-from-command-line – Tim Williams Oct 31 '12 at 20:43
  • Its called "Uniformance". More importantly I want to open the file rather than running the macro. If I can open the file then I can write a code to run the macro. I actually already have a code that runs the macro – user1783633 Oct 31 '12 at 21:48
  • To make the question simple. Is there a way I open open Excel 2003 and then open a file in it using a batch file or WSH code? I know I can open the file directly from a batch command but it will open the file in the default version of excel but I would rather wanna open my own preferred version of excel first and then open the file in it. – user1783633 Oct 31 '12 at 21:55
  • Did you look at the link I posted? Seems like Uniformance may just be an add-in for Excel, so you could open Excel, load the add-in, and then open your file. The code at the link should give you some idea of how to do that. – Tim Williams Oct 31 '12 at 22:22
  • Yes I did but its not helpful. Thats the second part of something I wanna do. Uniformance is already loaded in excel. Once I click on the desktop icon "Excel with Uniformace" excel opens up with uniformance already loaded in. Now the problem is that how to load/open a file that I want in that excel using a batch command. – user1783633 Nov 01 '12 at 21:55
  • What is the path that the desktop shortcut points to? – Tim Williams Nov 01 '12 at 22:32
  • It points to the location of the program which is run virtually. Excel with uniformance is not installed on my computer. I run it virtually. I can open the program with a batch command though. – user1783633 Nov 02 '12 at 17:03
  • First I was thinking if I can change the default program that opens my excel files to Uniformance Excel then it will open every excel file with Uniformance excel when I click on it but Uniformance excel is not installed on my computer so I cant even do that – user1783633 Nov 02 '12 at 17:05
  • How **exactly** are you running the add-in "virtually"? What does that mean? – Tim Williams Nov 02 '12 at 17:45
  • Add-in a programmed into excel. Its a module coded in vba and sql code thats in excel. On my computer I have Excel 2010 installed but I can access Excel 2003 with uniformance (which is on a server) virtually. – user1783633 Nov 02 '12 at 17:48
  • But that doesn't even matter I think. If we even forget about the add-in. The simple question is that how to open a file into excel. Instead of opening a certain file by clicking on it I wanna open the excel 2003 first and then open a file in it. Its a simple question. – user1783633 Nov 02 '12 at 17:51
  • More specific - how exactly do you access this remote Excel installation? Virtual desktop, Citrix, ??? It would help if you wuold post the actual path of the desktop shortcut you use (feel free to edit a bit to change details). – Tim Williams Nov 02 '12 at 17:51
  • It's not a simple question if the Excel in question is not running locally on your PC. – Tim Williams Nov 02 '12 at 17:52
  • like you mentioned in your comment above "Did you look at the link I posted? Seems like Uniformance may just be an add-in for Excel, so you could open Excel, load the add-in, and then open your file. The code at the link should give you some idea of how to do that" Thats exactly what I wanna do MINUS the loading the macro. I wanna open excel first and then open the file. I am looking for a batch command or WSH code which lets me OPEN A FILE in an already open Excel 2003 (I know the command to open Excel 2003) – user1783633 Nov 02 '12 at 17:52
  • Sorry - I don't know anything about App-V. – Tim Williams Nov 02 '12 at 18:58

1 Answers1

0

If you already have a running instance of excel then you can use something like this:

Dim XL
On Error Resume Next
Set XL = GetObject(, "Excel.Application")
On Error Goto 0

If Not TypeName(XL) = "Empty" Then
    XL.Workbooks.Open "path to your file here"
    XL.Run "path to your macro here"
End If

NOTE: if there are multiple instances of excel open, then the one returned can't easily be predicted.

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • I can't use this line of the code XL.Workbooks.Open "path to your file here" because if I put path of my file there then it will open the file in Excel 2010 which I dont want. Thats why I wanna open the Excel 2003 first and then open the file in it. Running the macro is not as important as opening the file in Excel 2003. – user1783633 Nov 02 '12 at 18:50
  • Since you refuse to answer my questions about how **exactly** you're running this remote version of Excel 2003, I'm not sure how you expect me to help you here. If you want to launch Excel programmatically then `CreateObject()` is how you'd typically do it, as described in the link I posted. however, that's not going to work if the application you want to open isn't installed locally. – Tim Williams Nov 02 '12 at 18:54
  • I didn't refuse to answer your question. I answered it. Anyways Thanks for all your help! Appreciate that. – user1783633 Nov 02 '12 at 19:14