|
-
Aug 18th, 2008, 03:43 PM
#1
Thread Starter
New Member
[RESOLVED] Opening Specific Version of Excel
I'm opening an instance of Excel to import data from a workbook using the following approach in VBA:
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlWSheet As Excel.Worksheet
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Open(FileName, False)
Set xlWSheet = xlBook.Worksheets(1)
The problem is that the workbook is an Excel 2003 document, but the machine running the code has both 2003 and 2007 versions of Excel. The Excel instance opens the document in 2007 causing errors, which crash the code.
Is there a simple way of specifying in code which version of Excel to create an instance of?
-
Aug 18th, 2008, 03:54 PM
#2
Re: Opening Specific Version of Excel
The problem is that the workbook is an Excel 2003 document, but the machine running the code has both 2003 and 2007 versions of Excel.
Both Cannot exist together without giving errors... you will have to uninstall one of them...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Aug 18th, 2008, 04:01 PM
#3
Thread Starter
New Member
Re: Opening Specific Version of Excel
Actually they exist together fine as long as I open the Excel version that I want first and then choose the document that I want to work with. Unisntallation is unfortunately not an option.
-
Aug 18th, 2008, 04:29 PM
#4
Re: Opening Specific Version of Excel
you could shell with full path and filename, to open the correct version of excel then use getobject(filename) to to work with that instance of excel
alternatively you could create a shortcut to open that workbook in the correct version of excel
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 18th, 2008, 04:44 PM
#5
Re: Opening Specific Version of Excel
Actually I think you can do it fairly easily, just change this line:
Code:
Set xlApp = New Excel.Application
to this:
Code:
Set xlApp = CreateObject("Excel.Application.11")
The number at the end can be one of the following:
7 - Excel 95
8 - Excel 97
9 - Excel 2000
10 - Excel XP
11 - Excel 2003
..and presumably 12 for Excel 2007, but I haven't checked yet.
-
Aug 19th, 2008, 04:15 PM
#6
Thread Starter
New Member
Re: Opening Specific Version of Excel
Thanks for the suggestions guys. The suggestion by si_the_geek should have worked, but it didn't. Makes me think the end users are doing something strange (works fine on my machine since I don't have 2007 on mine).
I'll let you all know how it turns out.
-
Aug 19th, 2008, 04:18 PM
#7
Re: Opening Specific Version of Excel
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 19th, 2008, 09:31 PM
#8
Re: Opening Specific Version of Excel
Install multiple versions of Excel (and Access too) on the same machine will give terrible headaches for novice users.
Specify version xx in CreateObject("Excel.Application.xx") won't help.
The culprit is even with 2 versions of Excel installed (2003=11 & 2007=12), the registry contains only one ProgID entry for Excel.
To switch it manually, run one of these shortcuts:
"C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE" /regserver
or
"C:\Program Files\Microsoft Office\OFFICE12\EXCEL.EXE" /regserver
To switch it programmatically, you need to have a piece of code to change the value of this registry entry:
HKEY_CLASSES_ROOT\CLSID\{00024500-0000-0000-C000-000000000046}\ProgID
to either "Excel.Application.11" or "Excel.Application.12"
before using CreateObject("Excel.Application").
-
Aug 20th, 2008, 10:37 AM
#9
Thread Starter
New Member
Re: Opening Specific Version of Excel
Thanks for all the great suggestions. It works fine now. The problem came down to source files being sent to us as Excel 2.1 (don't ask me) and VBA was having problems opening them in Excel 2003. Having Excel 2007 on the same machine just muddied the waters even more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|