8

I have two versions of excels(2010 and 2016) installed on my machine. I would like to run a vbscript on excel 2016.

However, the

CreateObject("Excel.Application") 

only creates excel 2010. How can i change this to 2016?

matt
  • 447,615
  • 74
  • 748
  • 977
Ray Lin
  • 97
  • 2
  • possible duplicate of [How to open specific version of Word 2007/2010 in Excel](https://stackoverflow.com/q/12073152/995714) – phuclv Mar 04 '18 at 13:10
  • AFAIK, multiple versions of Office products on the same machine(+instance) are not supported, and this is one of the big reasons why. – RBarryYoung Mar 08 '18 at 23:01
  • I think your problem is that excel 2010 is the default program to open excel extensions.Tray to make excel 2016 the default program. and feedback me please with the result.Sallam. – hollopost 1 hour ago – hollopost Oct 18 '18 at 19:12

2 Answers2

4

For 2016, you could try CreateObject("Excel.Application.16").

However, see the comments below as this is not guaranteed to work for recent versions. This has worked for me before for versions up-to and including 2010.

Note that earlier versions don't have such a straightforward correspondence, 2016 => 16. For example, I believe Office 2010 => 14.

Andy G
  • 18,518
  • 5
  • 42
  • 63
  • 2
    Hi Andy, thanks for the response. It did not seem to make a difference. It still opened in 2010. – Ray Lin Jan 18 '18 at 20:48
  • 1
    "A common perception for Office Automation when you have multiple versions of Office installed on a system is that you can dictate which version loads by using a specific version-dependent PROGID (for example, that `Excel.Application.9` loads Excel 2000, `Excel.Application.10` loads Excel 2002 and `Excel.Application.11` loads Office Excel 2003)... – phuclv Mar 04 '18 at 12:56
  • 2
    [... However, this is not correct. Excel 2000 and later versions of Excel share the same CLSID, so the version that loads with these PROGIDs depends solely on which version was last installed."](https://support.microsoft.com/en-us/help/292491/office-automation-when-multiple-versions-of-office-are-installed) – phuclv Mar 04 '18 at 12:56
  • Thank you @LưuVĩnhPhúc. I have added a note as I understand now that this is not supposed to work. I still think it worth mentioning as it has worked for me up-to 2010, and even (IIRC) 2013. – Andy G Mar 05 '18 at 08:45
3

I believe the issue you may be running into is of 32bit and 64bit.

32bit: c:\Windows\SysWOW64\wscript.exe
64bit: c:\Windows\System32\wscript.exe

When you run a 32bit vbscript process (the default) the mapping automatically takes the 32bit excel version.

So you should try running it with the 64bit VBScript

And yes you would want to use CreateObject("Excel.Application.16")

Tarun Lalwani
  • 124,930
  • 8
  • 149
  • 214
  • [`SysWOW64` is for 32-bit processes](https://stackoverflow.com/q/28942923/995714). 64-bit processes are stored in system32 – phuclv Mar 03 '18 at 05:31
  • @LưuVĩnhPhúc, don't use windows so got a bit confused. Will update the answer. Thanks for the correction :-) – Tarun Lalwani Mar 03 '18 at 05:31
  • Hi, thanks for the info. I'm having the same problem asOP and not familiar with VBS. Both Excel 2010 & 2016 is running in 32-bit. – aaa Mar 05 '18 at 00:43
  • @ppz, please join this chat room https://chat.stackoverflow.com/rooms/166220/discussion-vbscript-create-excel-2016-object – Tarun Lalwani Mar 05 '18 at 07:36