VBScript create excel 2016 object
Asked Answered
P

2

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?

Preconcert answered 18/1, 2018 at 15:25 Comment(3)
possible duplicate of How to open specific version of Word 2007/2010 in ExcelMurguia
AFAIK, multiple versions of Office products on the same machine(+instance) are not supported, and this is one of the big reasons why.Kainite
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 agoPeyton
P
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.

Paigepaik answered 18/1, 2018 at 15:27 Comment(4)
Hi Andy, thanks for the response. It did not seem to make a difference. It still opened in 2010.Preconcert
"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)...Murguia
... 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."Murguia
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.Paigepaik
O
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")

Oscitancy answered 3/3, 2018 at 5:28 Comment(4)
SysWOW64 is for 32-bit processes. 64-bit processes are stored in system32Murguia
@LưuVĩnhPhúc, don't use windows so got a bit confused. Will update the answer. Thanks for the correction :-)Oscitancy
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.Footmark
@ppz, please join this chat room chat.stackoverflow.com/rooms/166220/…Oscitancy

© 2022 - 2024 — McMap. All rights reserved.