Upgrading C++ applications to use Office 2007

I have a C++ application in VS2005 that generates Excel spreadsheets.  We are upgrading to VS2008 and from Office 2003 to Office 2007.

The code to import the correct version of Office is pasted here:


//#define USE_MS_OFFICE_2000
//#define USE_MS_OFFICE_2002
#define USE_MS_OFFICE_2003

#if defined(USE_MS_OFFICE_97) // Office 97 (Office v8)

#import "c:\program files\microsoft office\office\mso97.dll" no_namespace rename("DocumentProperties", "DocumentPropertiesXL")
#import "c:\program files\common files\microsoft shared\vba\vbeext1.olb" no_namespace
#import "c:\program files\microsoft office\office\Excel8.olb" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces

#elif defined(USE_MS_OFFICE_2000)      // Office 2000 (Office v9)

#import "C:\Program Files\Microsoft Office\Office\mso9.dll" no_namespace rename("DocumentProperties", "DocumentPropertiesXL")
#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\vbe6ext.olb" no_namespace
#import "C:\Program Files\Microsoft Office\Office\Excel9.olb" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces

#elif defined(USE_MS_OFFICE_2002)      // Office XP (2002) (Office v10)

#import "C:\Program Files\Common Files\Microsoft Shared\office10\mso.dll" rename("DocumentProperties", "DocumentPropertiesXL") rename("RGB", "RBGXL")
#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\vbe6ext.olb"
#import "C:\Program Files\Microsoft Office\Office10\EXCEL.EXE" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") rename("ReplaceText", "ReplaceTextXL") rename("CopyFile", "CopyFileXL") no_dual_interfaces

#elif defined(USE_MS_OFFICE_2003) // Office 2003 (Office v11) (Will give error (actually a warning) that you need W2K or higher to run the result)

#import "C:\Program Files\Common Files\Microsoft Shared\OFFICE11\mso.dll" rename("RGB", "MSRGB")
#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB" raw_interfaces_only, rename("Reference", "ignorethis"), rename("VBE", "testVBE")
#import "C:\Program Files\Microsoft Office\OFFICE11\excel.exe" exclude("IFont", "IPicture") rename("RGB", "ignorethis"), rename("DialogBox", "ignorethis"), rename("VBE", "testVBE"), rename("ReplaceText", "EReplaceText"), rename("CopyFile","ECopyFile"), rename("FindText", "EFindText"), rename("NoPrompt", "ENoPrompt") no_dual_interfaces


#error Please define one of the USE_MS_OFFICE_xx definitions to select which MS Office version should be used.


I get the following error trying to compile:

1>.\ExcelExport.cpp(32) : fatal error C1083: Cannot open type library file: 'C:\Program iles\Microsoft Office\OFFICE11\excel.exe': No such file or directory

Does anyone know what the import statements for Office 2007 look like?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You should be on the right track (double checked with http://www.codeproject.com/KB/wtl/WTLExcel.aspx - ""). Have you  checked whether 'excel.exe' really resides there and tried double backslashes, e.g
#import "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE11\\MSO.DLL"

#import "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE"

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
>>>> Cannot open type library file: 'C:\Program iles\Microsoft Office\OFFICE11

Firstly, you should take all error messages literally. So if you copied the original error message from your output window, the error message surely is right casue you probably have no folder named  'C:\Program iles' but only 'C:\Program Files'.

So correct the path specified in line 32 of export.cpp.
jribbleAuthor Commented:
I think I copied the error incorrectly and dropped the F in "Program iles".  The error was not unexpected, I was just wondering if anyone was aware of the equivalent import statements for Office 2007.
As above: They should be the same...
jribbleAuthor Commented:
The files were actually located in the OFFICE12 directory.  Once I made that adjustment, it compiled and worked fine.

#import "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE12\\MSO.DLL"
#import "C:\\Program Files\\Microsoft Office\\OFFICE12\\EXCEL.EXE"
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.