Search code examples
ms-accessvbams-access-2010ms-access-2013

MS Access Reference to LATEST Excel/Word/etc


I haven't seen this exact question yet:

I have multiple installations of MS Office (don't ask, just need it!). Anyway, I've developed a database that will create and interact with Excel sheets and Word documents. Currently, when creating these files, I'm using something like Excel.14 or Word.14 to specify Office 2010 documents. We are upgrading to Office 2013, and though I will still have Office 2010 installed, I want VBA to point to Word.15 but I don't want to hard code it.

I don't want to edit the code each time we upgrade. Is there a way to ensure that these references will ALWAYS pick the latest version of installed software?

Thanks for the help!

...Scotty


Solution

  • You might be able to use late binding to achieve this. Instead of setting a Reference in the project and using...

    Dim objExcel As New Excel.Application
    Dim objWord As New Word.Application
    

    ...you could try omitting the project Reference and use

    Dim objExcel As Object, objWord As Object
    Set objExcel = CreateObject("Excel.Application")
    Set objWord = CreateObject("Word.Application")