?
Solved

Excel 2010 Automation Using C++

Posted on 2013-01-08
2
Medium Priority
?
1,895 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

800 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