?
Solved

Excel 2010 Automation Using C++

Posted on 2013-01-08
2
Medium Priority
?
1,944 Views
Last Modified: 2013-01-29
I recently upgraded to Visual Studio 2010 and Office 2010.  My c++ program that compiled correctly with Excel 2003 no longer compiles correctly and throws many errors.  I have pasted in below some of these errors.  I have also pasted in the #imports and #includes.  I these were correct.

#include <stdafx.h>
#include <fstream>
#include <string>
#include <conio.h>
#include <string.h>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
#include <comdef.h>
#include <windows.h>
#include <Lmcons.h>
#include <stdio.h>
#include <tchar.h>

#import \
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\vwd\mso.dll" \
rename("DocumentProperties", "DocumentPropertiesXL") \
rename("RGB", "RBGXL")

#import \
"C:\Program Files (x86)\Common Files\microsoft shared\VBA\VBA7\VBE7.DLL" \
rename("EOF", "EOFXL") rename("RGB", "RGBXL") \
rename("GetObject", "GetObjectXL")

#import "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.exe" \
rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") \
rename("DocumentProperties", "DocumentPropertiesXL") \
rename("ReplaceText", "ReplaceTextXL") \
rename("CopyFile", "CopyFileXL") \
exclude("IFont", "IPicture") no_dual_interfaces

#import "C:\Program Files (x86)\Common Files\microsoft shared\DAO\dao360.dll" \
rename("EOF", "DAOEOF")




The erros are produced from the files:

\debug\vbe7.tlh(1136): warning C4146: unary minus operator applied to unsigned type, result still unsigned
\debug\excel.tlh(2347): error C2146: syntax error : missing ';' before identifier 'GetRBGXL'
\debug\excel.tlh(2347): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(2347): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(2347): warning C4183: 'GetRBGXL': missing return type; assumed to be a member function returning 'int'
\debug\excel.tlh(2349): error C2061: syntax error : identifier 'MsoRGBType'
\debug\excel.tlh(2555): error C2146: syntax error : missing ';' before identifier 'Crop'
\debug\excel.tlh(2555): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(2555): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(2590): error C2146: syntax error : missing ';' before identifier 'GetTransparencyColor'
\debug\excel.tlh(2590): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(2590): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(2590): warning C4183: 'GetTransparencyColor': missing return type; assumed to be a member function returning 'int'
\debug\excel.tlh(2592): error C2061: syntax error : identifier 'MsoRGBType'
\debug\excel.tlh(2596): error C2146: syntax error : missing ';' before identifier 'GetCrop'
\debug\excel.tlh(2596): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(2596): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(2596): warning C4183: 'GetCrop': missing return type; assumed to be a member function returning 'int'
\debug\excel.tlh(2927): error C2146: syntax error : missing ';' before identifier 'GradientStops'
\debug\excel.tlh(2927): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(2927): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(2937): error C2146: syntax error : missing ';' before identifier 'PictureEffects'
\debug\excel.tlh(2937): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(2937): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(2992): error C2146: syntax error : missing ';' before identifier 'GetGradientStops'
\debug\excel.tlh(2992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(2992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(2992): warning C4183: 'GetGradientStops': missing return type; assumed to be a member function returning 'int'
\debug\excel.tlh(3014): error C2146: syntax error : missing ';' before identifier 'GetPictureEffects'
\debug\excel.tlh(3014): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(3014): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(3014): warning C4183: 'GetPictureEffects': missing return type; assumed to be a member function returning 'int'
\debug\excel.tlh(3115): error C2146: syntax error : missing ';' before identifier 'Diagram'
\debug\excel.tlh(3115): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\debug\excel.tlh(3115): error C2208: 'Excel::Diagram' : no members defined using this type
\debug\excel.tlh(3115): fatal error C1903: unable to recover from previous error(s); stopping compilation
0
Comment
Question by:BigDaddyG1981
2 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 2000 total points
ID: 38757994
Hi BigDaddyG1981,

I'm not sure, but maybe you import the wrong mso.dll. You could try using this path instead:
C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14

BTW: Is this managed or unmanaged C++?

ZOPPO
0
 
LVL 25

Expert Comment

by:chaau
ID: 38808222
If you want to continue to go in this direction you would need to fix the errors one by one. I will first guide you through the fixing your existing problems.

To fix the errors in Excel.tlh(2347) you need to add rename("RGB", "RBGXL") to your #import "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.exe"

Then to fix the errors in Excel(2349) you would either do rename("Crop", "CropXL") \ or use exclude() for this interface altogether.

But this is a very painful process, because you would have to add many more renames and excludes.

You would be better off if you import your old Office2003 interface. I think in this case the program will continue to work with newer versions of Excels on the user PCs

Even better, use a ClassWizard to import the Excel from type library. It will then generate files excelxx.h and excelxx.cpp (xx is Excel Version, I guess it will be 14 in your case). Once it is done, the wizard will wrap all the OLE calls into nice classes that are much easier to work with. But this solution will require re-coding of your other parts of the program
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Suggested Courses

850 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