Google Answers Logo
View Question
 
Q: OLE / COM / Automation in Excel ( No Answer,   0 Comments )
Question  
Subject: OLE / COM / Automation in Excel
Category: Computers > Programming
Asked by: veil775-ga
List Price: $10.00
Posted: 26 Jan 2006 07:58 PST
Expires: 25 Feb 2006 07:58 PST
Question ID: 437889
GAers:

I?m trying to use VC to open Excel and manipulate a worksheet.  I?m
importing Excel9.OLB, which can be located in C:\Program
Files\Microsoft Office\Office\ -- assuming the default installation
folder.  Depending on your version of Excel, the OLB filename might be
slightly different... ExcelXX.OLB.  I encourage you to look at it
using OLE/COM Object Viewer.

I can successfully instantiate an instance of _Application using
CoCreateInstance().  From there, I can get Workbooks, _Workbook,
Sheets, and _Worksheet.  However, the problem occurs when I try to
call the _Worksheet method called get_Range().  It?s defined as
follows...

 _Worksheet::get_Range(VARIANT Cell1, VARIANT Cell2, RANGE **RHS).

I make my call this way...

// sheet is declared/initialize prior

Range *range = NULL;
sheet->get_Range(_variant_t(?A1?), _variant_t(?A2?), &range);

After I have the range, I need to call the method Activate(VARIANT
*RHS).  However, I cannot call methods to that variable unless I use
Invoke(), DISPPARAMS, etc, which makes my code very bloated.  How can
I create an object of type IRange, which is the interface to make easy
method calls?

I?ve tried various ways?

// sheet is obtained before hand

IRange *range = NULL;
IDispatch *temp = NULL;

sheet->get_Range(_variant_t(?A1?), _variant_t(?A2?), (Range **)&temp);
temp->QueryInterface(__uuidof(Range), (void **)&range);

VARIANT var;	// var is just a return message indicating success or failure
VariantInit(&var);
range->Activate(&var);

This attempt does not work.  Again, any suggestions on how I can
create an object of type IRange, so I can easily call methods would be
much appreciated as calling Invoke() from the data type Range is
encumbering my code.

I thank you all for those who try to assist me in my endeavor.  Also,
I hope others find your solutions helpful if they -- too -- have the
same or similar problems.  Thank you once again.
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy