![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | How do I access different versions of Excel from one .NET executable? I want to use Visual Studio (2008, writing in VB.NET) to create an EXE file that will, among other things, read from and write to Excel workbooks. In particular, I want the program to work whether the machine has Office 2003 or Office 2007 installed. (Other versions of Excel would also be nice -- in particular 2010, when it comes out -- but those two are critical). I have no trouble accessing Excel 2007 on my own PC; however when I copy the EXE file to a PC with Office 2003 installed the program fails when it hits the Excel access code. (Note that VB.NET programs compiled on the other PC are able to read and write Excel 2003 files on that machine, so that's not the problem). I do know something about PIAs, although perhaps not enough. My project makes a COM reference to the Microsoft Excel 12.0 Office Library, which allows it to access Excel 2007. I believe that to access Excel 2003 I would need to reference the 11.0 library, which doesn't exist on my machine, so I can't reference it. Even if it did, I don't know if it's possible or would make sense to reference both libraries in the same project. So what do I do? My requirement seems very straightforward -- something that a lot of people would want to do. But I've looked around a bit without finding a way to do it. Indeed, I've found disturbing suggestions that I will need to compile a separate version of my program for each version of Office I want to be compatible with, which would be very unpleasant. (Just for starters, since you can't have two versions of Office on the same machine, I would need to get a second PC just for this!). I am really hoping that Microsoft has not made my life that difficult. So can anyone give me some advice, or point me to documentation that might help me out? -- John Brock jbrock@xxxxxx |
My System Specs![]() |
| | #2 (permalink) |
| | Re: How do I access different versions of Excel from one .NET executable? you can have multiple versions of Excel installed....and you'll then have access to each Excel library. your code should be able to instantiate Excel, and use the relevant library. "John Brock" <jbrock@xxxxxx> wrote in message news:gugb07$cdq$1@xxxxxx Quote: > I want to use Visual Studio (2008, writing in VB.NET) to create an > EXE file that will, among other things, read from and write to > Excel workbooks. In particular, I want the program to work whether > the machine has Office 2003 or Office 2007 installed. (Other > versions of Excel would also be nice -- in particular 2010, when > it comes out -- but those two are critical). > > I have no trouble accessing Excel 2007 on my own PC; however when > I copy the EXE file to a PC with Office 2003 installed the program > fails when it hits the Excel access code. (Note that VB.NET programs > compiled on the other PC are able to read and write Excel 2003 > files on that machine, so that's not the problem). > > I do know something about PIAs, although perhaps not enough. My > project makes a COM reference to the Microsoft Excel 12.0 Office > Library, which allows it to access Excel 2007. I believe that to > access Excel 2003 I would need to reference the 11.0 library, which > doesn't exist on my machine, so I can't reference it. Even if it > did, I don't know if it's possible or would make sense to reference > both libraries in the same project. > > So what do I do? My requirement seems very straightforward -- > something that a lot of people would want to do. But I've looked > around a bit without finding a way to do it. Indeed, I've found > disturbing suggestions that I will need to compile a separate > version of my program for each version of Office I want to be > compatible with, which would be very unpleasant. (Just for starters, > since you can't have two versions of Office on the same machine, > I would need to get a second PC just for this!). > > I am really hoping that Microsoft has not made my life that difficult. > So can anyone give me some advice, or point me to documentation > that might help me out? > -- > John Brock > jbrock@xxxxxx > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: How do I access different versions of Excel from one .NET executable? Hmmm..., are you *sure* you can have two (or more) versions of Office on the same machine? I could swear that I read somewhere this isn't possible. Anyway, to be certain I understand, you are saying that once I install both versions of Office (with both sets of PIAs), that my project should reference *both* the 11.0 and 12.0 versions of the Microsoft Excel Office Library, and the appropriate reference will be used depending on what is on a particular machine? But what will happen on *my* machine? The VB code that accesses Excel doesn't specify a version, so if both versions are available, which will be instantiated? Also, what happens to my file associations if I have two versions of Office? I'm pretty nervous about taking this route. Maybe there is some way I can install and reference the Office 2003 PIAs without actually installing Office 2003? In article <53F41560-5061-4D3A-925E-6F9E448CB120@xxxxxx>, Patrick Molloy <patrick_molloy@xxxxxx> wrote: Quote: >you can have multiple versions of Excel installed....and you'll then have >access to each Excel library. >your code should be able to instantiate Excel, and use the relevant library. > >"John Brock" <jbrock@xxxxxx> wrote in message >news:gugb07$cdq$1@xxxxxx Quote: >> I want to use Visual Studio (2008, writing in VB.NET) to create an >> EXE file that will, among other things, read from and write to >> Excel workbooks. In particular, I want the program to work whether >> the machine has Office 2003 or Office 2007 installed. (Other >> versions of Excel would also be nice -- in particular 2010, when >> it comes out -- but those two are critical). >> >> I have no trouble accessing Excel 2007 on my own PC; however when >> I copy the EXE file to a PC with Office 2003 installed the program >> fails when it hits the Excel access code. (Note that VB.NET programs >> compiled on the other PC are able to read and write Excel 2003 >> files on that machine, so that's not the problem). >> >> I do know something about PIAs, although perhaps not enough. My >> project makes a COM reference to the Microsoft Excel 12.0 Office >> Library, which allows it to access Excel 2007. I believe that to >> access Excel 2003 I would need to reference the 11.0 library, which >> doesn't exist on my machine, so I can't reference it. Even if it >> did, I don't know if it's possible or would make sense to reference >> both libraries in the same project. >> >> So what do I do? My requirement seems very straightforward -- >> something that a lot of people would want to do. But I've looked >> around a bit without finding a way to do it. Indeed, I've found >> disturbing suggestions that I will need to compile a separate >> version of my program for each version of Office I want to be >> compatible with, which would be very unpleasant. (Just for starters, >> since you can't have two versions of Office on the same machine, >> I would need to get a second PC just for this!). >> >> I am really hoping that Microsoft has not made my life that difficult. >> So can anyone give me some advice, or point me to documentation >> that might help me out? >> -- >> John Brock >> jbrock@xxxxxx >> -- John Brock jbrock@xxxxxx |
My System Specs![]() |
| | #4 (permalink) |
| | Re: How do I access different versions of Excel from one .NET executable? Hello John, Yes that is the case. You cannot reference the later PIA because these contain new functionality not yet available when the previous version came out. But the old excel functions are still built into the new executables, so the older PIA will work regardless of later upgrades. Until MS decides to deprecate such functions in later versions Knowing that we'll have a 64 bit version of the next Office, I guess that there will be a break in backwards compatibility as I doubt that a 32 bit PIA for Excel 2003 would be able to load Excel 2010 64 bit. It should still work with the 32 bit version though. (not verified nor tested) Jesse Quote: > OK, you are saying that if my program references the Office 2003 PIA > (Microsoft Excel 11.0 Object Library) this will work with later > versions of Excel, but not the reverse. This is actually the opposite > of what I would have expected. Any idea what is going on here? And > is this likely to hold when Office 2010 comes out. > > In article <C9727ED3-D7AB-4315-AB65-2EFB8E40908E@xxxxxx>, > Andreas Johansson <afjohanssonREMOVE@xxxxxx> wrote: > Quote: >> Usually it is most easy to install the earliest version of excel you >> want to use on the development machine. Then reference that version >> instead in your project. >> >> You might be able to install them side by side so no need to >> uninstall 2007. >> Jesse Houwing jesse.houwing at sogeti.nl |
My System Specs![]() |
| | #5 (permalink) |
| | Re: How do I access different versions of Excel from one .NET executable? The general answer to this is to forget version-specific PIAs and use the late-binding scripting interfaces. It's pretty ugly, as you can see from this: http://support.microsoft.com/kb/302902 but it's been used for years by scripting clients. -- Phil Wilson "John Brock" <jbrock@xxxxxx> wrote in message news:gugb07$cdq$1@xxxxxx Quote: >I want to use Visual Studio (2008, writing in VB.NET) to create an > EXE file that will, among other things, read from and write to > Excel workbooks. In particular, I want the program to work whether > the machine has Office 2003 or Office 2007 installed. (Other > versions of Excel would also be nice -- in particular 2010, when > it comes out -- but those two are critical). > > I have no trouble accessing Excel 2007 on my own PC; however when > I copy the EXE file to a PC with Office 2003 installed the program > fails when it hits the Excel access code. (Note that VB.NET programs > compiled on the other PC are able to read and write Excel 2003 > files on that machine, so that's not the problem). > > I do know something about PIAs, although perhaps not enough. My > project makes a COM reference to the Microsoft Excel 12.0 Office > Library, which allows it to access Excel 2007. I believe that to > access Excel 2003 I would need to reference the 11.0 library, which > doesn't exist on my machine, so I can't reference it. Even if it > did, I don't know if it's possible or would make sense to reference > both libraries in the same project. > > So what do I do? My requirement seems very straightforward -- > something that a lot of people would want to do. But I've looked > around a bit without finding a way to do it. Indeed, I've found > disturbing suggestions that I will need to compile a separate > version of my program for each version of Office I want to be > compatible with, which would be very unpleasant. (Just for starters, > since you can't have two versions of Office on the same machine, > I would need to get a second PC just for this!). > > I am really hoping that Microsoft has not made my life that difficult. > So can anyone give me some advice, or point me to documentation > that might help me out? > -- > John Brock > jbrock@xxxxxx > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: How do I access different versions of Excel from one .NET executable? In article <guhm3l$6kg$1@xxxxxx>, John Brock wrote: Quote: > Hmmm..., are you *sure* you can have two (or more) versions of > Office on the same machine? I could swear that I read somewhere > this isn't possible. However, the replies you're getting seem mostly directed at "Can I have both installed on one PC" and your question is more about "Can I develop in Visual Studio for both on one PC?" My understanding is that you can't (or that you'd need to do at least half your dev in a virtual machine). I'd bring up the same questions in a group devoted to .NET/Visual Studio/VSTO. |
My System Specs![]() |
| | #7 (permalink) |
| | Re: How do I access different versions of Excel from one .NET executable? In article <VA.00004d9f.03d145c4@xxxxxx>, Steve Rindsberg <abuse@xxxxxx> wrote: Quote: >In article <guhm3l$6kg$1@xxxxxx>, John Brock wrote: Quote: >> Hmmm..., are you *sure* you can have two (or more) versions of >> Office on the same machine? I could swear that I read somewhere >> this isn't possible. Quote: >It is possible (but not supported). > >However, the replies you're getting seem mostly directed at "Can I have both >installed on one PC" and your question is more about "Can I develop in Visual >Studio for both on one PC?" > >My understanding is that you can't (or that you'd need to do at least half your >dev in a virtual machine). I'd bring up the same questions in a group devoted >to .NET/Visual Studio/VSTO. Usenet. Also, do you have any idea whether it is possible to install the Office 2003 PIAs on my machine, in addition to the PIAs that came with Office 2007, without actually installing Office 2003? It appears from what folks are saying that the earlier PIAs will work with later versions of Office, so if I could use those that would be the simplest thing. Of course, in the same vein, I could always uninstall Office 2007 and install Office 2003. That would be sad, but it would still beat having to buy another machine, or keep a duplicate code base on a virtual machine. :-( -- John Brock jbrock@xxxxxx |
My System Specs![]() |
| | #8 (permalink) |
| | Re: How do I access different versions of Excel from one .NET executable? Very interesting!!! I knew about reflection and late binding, but it didn't occur to me that they could be used for this. (I assume this method will work just as well for VB.NET as for C#)? Yes, coding would be ugly. I would especially miss Intellisense. But it looks like doing it this way would remove all version worries. (I'm not doing anything especially sophisticated with Excel, so whatever I need is going to be there in all versions). In addition, I wouldn't even have to worry about whether any PIAs were installed on the end user's machine (which is not guaranteed). Have I understood all this correctly? In practice I think I would end up coding everything first using the Excel PIA, just to see what all the calls ended up looking like, and then translating everything to late binding. Yes, ugly, but maybe the best way. Thanks! In article <8A0B503C-D329-4551-81A7-E4B5A11FEC43@xxxxxx>, Wilson, Phil <philw@xxxxxx> wrote: Quote: >The general answer to this is to forget version-specific PIAs and use the >late-binding scripting interfaces. It's pretty ugly, as you can see from >this: >http://support.microsoft.com/kb/302902 > >but it's been used for years by scripting clients. >-- >Phil Wilson Quote: >"John Brock" <jbrock@xxxxxx> wrote in message >news:gugb07$cdq$1@xxxxxx Quote: >>I want to use Visual Studio (2008, writing in VB.NET) to create an >> EXE file that will, among other things, read from and write to >> Excel workbooks. In particular, I want the program to work whether >> the machine has Office 2003 or Office 2007 installed. (Other >> versions of Excel would also be nice -- in particular 2010, when >> it comes out -- but those two are critical). >> >> I have no trouble accessing Excel 2007 on my own PC; however when >> I copy the EXE file to a PC with Office 2003 installed the program >> fails when it hits the Excel access code. (Note that VB.NET programs >> compiled on the other PC are able to read and write Excel 2003 >> files on that machine, so that's not the problem). >> >> I do know something about PIAs, although perhaps not enough. My >> project makes a COM reference to the Microsoft Excel 12.0 Office >> Library, which allows it to access Excel 2007. I believe that to >> access Excel 2003 I would need to reference the 11.0 library, which >> doesn't exist on my machine, so I can't reference it. Even if it >> did, I don't know if it's possible or would make sense to reference >> both libraries in the same project. >> >> So what do I do? My requirement seems very straightforward -- >> something that a lot of people would want to do. But I've looked >> around a bit without finding a way to do it. Indeed, I've found >> disturbing suggestions that I will need to compile a separate >> version of my program for each version of Office I want to be >> compatible with, which would be very unpleasant. (Just for starters, >> since you can't have two versions of Office on the same machine, >> I would need to get a second PC just for this!). >> >> I am really hoping that Microsoft has not made my life that difficult. >> So can anyone give me some advice, or point me to documentation >> that might help me out? >> -- >> John Brock >> jbrock@xxxxxx John Brock jbrock@xxxxxx |
My System Specs![]() |
| | #9 (permalink) |
| | Re: How do I access different versions of Excel from one .NET executable? On Fri, 15 May 2009 04:47:15 +0000 (UTC), jbrock@xxxxxx (John Brock) wrote: Quote: >In article <VA.00004d9f.03d145c4@xxxxxx>, >Steve Rindsberg <abuse@xxxxxx> wrote: Quote: >>In article <guhm3l$6kg$1@xxxxxx>, John Brock wrote: Quote: >>> Hmmm..., are you *sure* you can have two (or more) versions of >>> Office on the same machine? I could swear that I read somewhere >>> this isn't possible. Quote: >>It is possible (but not supported). >> >>However, the replies you're getting seem mostly directed at "Can I have both >>installed on one PC" and your question is more about "Can I develop in Visual >>Studio for both on one PC?" >> >>My understanding is that you can't (or that you'd need to do at least half your >>dev in a virtual machine). I'd bring up the same questions in a group devoted >>to .NET/Visual Studio/VSTO. >Can you suggest such a group? I didn't see anything like that on >Usenet. > >Also, do you have any idea whether it is possible to install the >Office 2003 PIAs on my machine, in addition to the PIAs that came >with Office 2007, without actually installing Office 2003? It >appears from what folks are saying that the earlier PIAs will work >with later versions of Office, so if I could use those that would >be the simplest thing. > >Of course, in the same vein, I could always uninstall Office 2007 >and install Office 2003. That would be sad, but it would still >beat having to buy another machine, or keep a duplicate code base >on a virtual machine. :-( search for 'office pia' there appear to be downloads for Office XP, Office 2003 and Office 2007. |
My System Specs![]() |
| | #10 (permalink) |
| | Re: How do I access different versions of Excel from one .NET executable? In article <guis4j$dl5$1@xxxxxx>, John Brock wrote: Quote: > In article <VA.00004d9f.03d145c4@xxxxxx>, > Steve Rindsberg <abuse@xxxxxx> wrote: Quote: > >In article <guhm3l$6kg$1@xxxxxx>, John Brock wrote: Quote: > >> Hmmm..., are you *sure* you can have two (or more) versions of > >> Office on the same machine? I could swear that I read somewhere > >> this isn't possible. Quote: > >It is possible (but not supported). > > > >However, the replies you're getting seem mostly directed at "Can I have both > >installed on one PC" and your question is more about "Can I develop in Visual > >Studio for both on one PC?" > > > >My understanding is that you can't (or that you'd need to do at least half your > >dev in a virtual machine). I'd bring up the same questions in a group devoted > >to .NET/Visual Studio/VSTO. whether it'll suit my needs. So far, it's more about PITA than PIA. YMMV, of course. Now that you're armed with that grain of salt ... Quote: > Can you suggest such a group? I didn't see anything like that on > Usenet. microsoft.public.vsnet.* microsoft.public.vstudio.* (*=various groups following the dot) Also look into the various microsoft.public.Office.Developer.* groups. Quote: > Also, do you have any idea whether it is possible to install the > Office 2003 PIAs on my machine, in addition to the PIAs that came > with Office 2007, without actually installing Office 2003? It > appears from what folks are saying that the earlier PIAs will work > with later versions of Office, so if I could use those that would > be the simplest thing. Quote: > Of course, in the same vein, I could always uninstall Office 2007 > and install Office 2003. That would be sad, but it would still > beat having to buy another machine, or keep a duplicate code base > on a virtual machine. :-( machines in seconds, or put it on an external or network drive and use it from either the physical or virtual machine. With at least some virtualization software, you can share a directory from the physical machine to a mapped drive on the VM. No code movement required at all. That vs uninstalling one Office version, installing the other? No contest. And that's not taking activation into account. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Ms access and excel has stopped working | Microsoft Office | |||
| Error when updating Access table from Excel Worksheet | VB Script | |||
| openning Excel or Access files directly | Vista General | |||
| openning Excel or Access files directly | Vista General | |||
| Access to executable downloads | Vista General | |||