Solved

Excel 2010 Automation Using C++

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

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.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

738 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