[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Excel 11.0 Automation in VC++

Posted on 2003-10-30
6
Medium Priority
?
1,551 Views
Last Modified: 2008-02-20
Can someone please send me a sample code for automating Excel 11.0 (Excel2003) using #import.

I made #import work for Excel 97 but #import "excel.exe" on Excel 11.0 is giving around 100 errors. Please let what is the #import statement for excel 11.0.

Thanks in Advance,
Kris
0
Comment
Question by:anjukkumar
[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
  • 3
  • 3
6 Comments
 
LVL 8

Expert Comment

by:martynjpearson
ID: 9656654
What are the errors? If you are #importing other things too, it could be that they need to be in different namespaces so that there aren't clashes where the same name is used twice.

Using MFC, I usually use Classwizard to create wrapper classes derived from COleDispatchDriver!
0
 

Author Comment

by:anjukkumar
ID: 9657721
A particular module was already developed using Excel 97.0 and here is the code that I used for Excel 97:

#import "C:\Program Files\Microsoft Office\Office\mso97.dll" no_namespace rename("DocumentProperties", "DocumentPropertiesXL")
#import "C:\Program Files\Common Files\Microsoft Shared\VBA\vbeext1.olb" no_namespace
#import "C:\Program Files\Microsoft Office\Office\excel8.olb" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces

Now we are upgrading our machines to Office 2003. I agree that using MFC is simpler but it is easy to replace the above code to use Excel 2003, otherwise I have change the code in all the places if I use MFC.

Here is the #import I am using:
#import "C:\Program Files\Microsoft Office\Office11\excel.exe"

Here are sample errors:

c:\krishn\research\excelaatmtn\debug\excel.tlh(1617) : error C2146: syntax error : missing ';' before identifier 'GetRBGXL'
c:\krishn\research\excelaatmtn\debug\excel.tlh(1617) : error C2501: 'MsoRGBType' : missing storage-class or type specifiers
c:\krishn\research\excelaatmtn\debug\excel.tlh(1619) : error C2061: syntax error : identifier 'MsoRGBType'

BTW, all the errors (around 100) are from  excel.tlh.

Thanks,
Kris
0
 
LVL 8

Accepted Solution

by:
martynjpearson earned 1500 total points
ID: 9658083
Here's something to try :

#import "C:\Program Files\Common Files\Microsoft Shared\Office10\MSO.DLL"
#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBa6\VBE6EXT.OLB"
#import "C:\Program Files\Microsoft Office\Office10\Excel.exe" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces

I did this using MS Office XP which is what I have on my machine, and I have to say that I haven't actually tried using the automation - getting it through the compiler was the hurdle I was hoping to get over!

I came up with the other imports by using the OLE View tool that comes with Visual Studio, to find out which type libraries contained the missing interfaces.

Hope this helps
Martyn
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:anjukkumar
ID: 9658255
Thanks Marttn for your time.

Excel.tlh has the following:

// Cross-referenced type libraries:
//
//  #import "C:\Program Files\Common Files\Microsoft Shared\OFFICE11\MSO.DLL"
//  #import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB"

So I included these 2 lines to my code but I still have the same errors.

However, if I use #import with "raw_interfaces_only" like this:
#import "C:\Program Files\Microsoft Office\Office11\excel.exe"   raw_interfaces_only rename("Rectangle", "_Rectangle") rename("Arc", "_Arc") rename("IFilter","_IFilter") rename("RGB", "RBGXL") rename("DialogBox", "DialogBoxXL")  rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces

I get rid of all the errors in excel.tlh but I get several errors from my code as I am not using raw_interfaces in my code. Here is an example error for the code ==== m_pWorkbook = m_pXL->Workbooks->Add((long)xlWorksheet);=====:
c:\krish\work\databasewriter\xls\xlsdatabase.cpp(43) : error C2039: 'Workbooks' : is not a member of '_Application'
        c:\krish\work\databasewriter\debug\excel.tlh(4249) : see declaration of '_Application'

Here is the definition of _Application in excel.tlh with raw_interface_only (no excel.tli is generated)
struct __declspec(uuid("000208d5-0000-0000-c000-000000000046"))
_Application : IDispatch
{};

If I don't use "raw_interface_only", then compiler generates excel.tli and also complete definition of _Application.

Please let me know what else I can try.

Thanks,
Kris
0
 
LVL 8

Expert Comment

by:martynjpearson
ID: 9658348
The documentation in the online help says...

The raw_interfaces_only attribute also causes the default prefix used in naming the non-property functions to be removed. Normally, the prefix is raw_. If this attribute is specified, the function names are directly from the type library.

So, I wonder if you can put this back by adding to the #import :

raw_method_prefix("raw_")

Martyn
0
 

Author Comment

by:anjukkumar
ID: 9658374
Here is what worked for me:

#import "C:\Program Files\Common Files\Microsoft Shared\OFFICE11\MSO.DLL" no_namespace rename("DocumentProperties", "DocumentPropertiesXL")
#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB" no_namespace
#import "C:\Program Files\Microsoft Office\Office11\excel.exe" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces


Previously I was putting #import on excel.exe first instead of putting it after MSO.DLL and VBE6EXT.OLB.

Martyn, I accept your 2nd comment as solution/answer eventhough it is not perfectly correct.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

650 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