Solved

Excel 2010 Automation Using C++

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

Accepted Solution

by:
Zoppo earned 500 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

743 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

18 Experts available now in Live!

Get 1:1 Help Now