Upgrading C++ applications to use Office 2007

Posted on 2010-03-31
Medium Priority
Last Modified: 2013-12-14
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?


Question by:jribble
  • 2
  • 2
LVL 86

Accepted Solution

jkr earned 2000 total points
ID: 29211200
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

LVL 39

Expert Comment

ID: 29214935
>>>> 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.

Author Comment

ID: 29223399
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.
LVL 86

Expert Comment

ID: 29225128
As above: They should be the same...

Author Comment

ID: 29787343
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"

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question