none
vba 2010 how to select correct version of word on multi-installed system? RRS feed

  • Question

  • I have a workstation that requires both Word 2003 and Word 2010 be installed. I need to run a vba 2010 app that converts a few hundred thousand files on the workstation from prior version (wordperfect) to PDF.  When I attempt to run the Application.ExportAsFixedFormat method it fails because the Application instantiation always chooses the Word 2003 version even though Word 2010 is the default.  As Word 2003 does not support conversion to PDF, my app fails. 

    I know how to determine which version is active (Application.Version), but is there any way I can tell the system I want the Word 2010 version instatiated instead?

    Imports Microsoft.Office.Interop.Word

    <snip>

    Dim objApp as Word.Application

    Current Namespaces Referenced:

    Microsoft Office 14.0 Object Library v2.5

    Microsoft Word 12.0 Object Library v8.4 (highest available in Visual Studio Express 2010 I have loaded)

    Fallback is to rebuild the workstation with only Office 2010 and Visual Studio Express 2010 and then rebuild back to support both which I really don't want to do...

    • Moved by Carl Cai Thursday, February 13, 2014 2:00 AM (form vb.net)More related to suggested forum
    Thursday, February 13, 2014 12:53 AM

Answers

  • It's a Registry setting, but a different one than for documents (which have a different one than templates, etc.) Basically, although each version is installed with its own ClassId, when a call is made to Word.Application OLE looks in just one place for the information to the *.exe. The version of Office/Word with "priority" is the version that's written into that Registry key - all versions share the same key. That's the reason for the behavior.

    While it's possible to change this (although recently the keys are in binary rather than plain text, so it's not so simple anymore), when an Office application from a different version is started it will tend to overwrite the key (re-register itself).

    If you search Word.Application in the Registry (CLSID hive) you'll find the entry that's used. This looks up the CLSID, which in turn contains the path to the winword.exe file.

    As far as documentation goes, see http://support.microsoft.com/kb/218861,the section "Inserting Office OLE objects into other programs". The OLE support uses the same Registry entry as for linking to the OLE Server app.

    Note that this question is not new. There's a fairly in-depth discussion on how all this works in the General Office Development forum, as I recall, with MSFT participation. Unfortunately, I'm not turning it up at the moment...


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by jkmassey Thursday, February 13, 2014 7:09 PM
    Thursday, February 13, 2014 6:34 PM
    Moderator

All replies

  • Hi,

    I have moved this thread to Word for Developers forum for more dedicated supports.

    Thanks for your understanding.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, February 13, 2014 2:01 AM
  • I don't believe you understood the question.  It is not a Word developer question. It is a VB 2010 question.  How do you get "Dim objApp as Word.Application" to select a specific version of Word when multiple versions are installed so that when you run "objApp.Documents.Open(...)" or a similar Word.Application then it selects Word 2010 over any other installed version of Word?

    This is not about writing a macro or formatting a document.  This is about controlling VB 2010 in the Microsoft.Office.Interop.Word namespace.


    jkmassey

    Thursday, February 13, 2014 2:42 PM
  • Office is not designed to be used in parallel, although there's nothing that stops the user from installing multiple versions. But the way Office is registered in Windows makes things difficult, as you've discovered.

    The only way, really, is for you to determine the file path to the winword.exe file in order to start ("shell") the one you want.
     


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, February 13, 2014 3:08 PM
    Moderator
  • So, there is no way for  "Dim objApp as Word.Application" to select which version it instantiates?

    Does anyone know how the association takes place?  I have Word 2010 set up as my default version if you just attempt to open a word document.  Why doesn't VB work off the same association?


    jkmassey

    Thursday, February 13, 2014 4:20 PM
  • It's a Registry setting, but a different one than for documents (which have a different one than templates, etc.) Basically, although each version is installed with its own ClassId, when a call is made to Word.Application OLE looks in just one place for the information to the *.exe. The version of Office/Word with "priority" is the version that's written into that Registry key - all versions share the same key. That's the reason for the behavior.

    While it's possible to change this (although recently the keys are in binary rather than plain text, so it's not so simple anymore), when an Office application from a different version is started it will tend to overwrite the key (re-register itself).

    If you search Word.Application in the Registry (CLSID hive) you'll find the entry that's used. This looks up the CLSID, which in turn contains the path to the winword.exe file.

    As far as documentation goes, see http://support.microsoft.com/kb/218861,the section "Inserting Office OLE objects into other programs". The OLE support uses the same Registry entry as for linking to the OLE Server app.

    Note that this question is not new. There's a fairly in-depth discussion on how all this works in the General Office Development forum, as I recall, with MSFT participation. Unfortunately, I'm not turning it up at the moment...


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by jkmassey Thursday, February 13, 2014 7:09 PM
    Thursday, February 13, 2014 6:34 PM
    Moderator
  • THank you Cindy.  I didn't find it either in my searches.  I figured I couldn't be the first person to encounter this.  Especially thanks for the KB link.  I also figured it was a registry hack but for this little job it just wasn't worth trying to work it out myself.  I mean, I'm retired since 2005.... lol

    jkmassey

    Thursday, February 13, 2014 7:08 PM
  • Hi jkmassey,

    Take a look at the following url - it appears to answer your question. I am going to try it myself today as I have the same issue. Will let you know if it works!

    The short answer is to use late binding and refer to

    Set wrdObj = CreateObject ("word.application.14"), which will only work if you have Office 2010 installed but seems to bypass the generic Word class key in the registry.

    http://books.google.co.nz/books?id=dtSdrjjVXrwC&pg=PA687&lpg=PA687&dq=word.application+2003+and+2010+installed&source=bl&ots=yUl6gmnwSp&sig=PoEjvFYc5FVQ5kJLpn7H-8uu0Mk&hl=en&sa=X&ei=eu4hU6etNYn0lAWmuIDwBQ&ved=0CDAQ6AEwAQ#v=onepage&q=word.application%202003%20and%202010%20installed&f=false

    Thursday, March 13, 2014 5:55 PM