Solved

Excel 2010 Automation Using C++

Posted on 2013-01-08
2
1,811 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 500 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 24

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now