There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer cpu crash dell desktop driver drivers dvd error excel external hard drive firefox format freezes freezing hard drive hardware hijackthis internet internet explorer ipod itunes laptop malware mouse network networking outlook 2007 power printer problem ram router screen slow sound trojan upgrade usb virus vista vista 32-bit windows windows xp winxp wireless
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Question about the automation between C++ and Excel , Thanks for help !


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
tonyhu's Avatar
Junior Member with 1 posts.
 
Join Date: Oct 2004
Experience: Advanced
25-Oct-2004, 10:18 PM #1
Question Question about the automation between C++ and Excel , Thanks for help !
Dear Gurus
First thanks in advance for your help.
I have worked on a c++ project which has an automation connection with the excel app( create an excel app, then open a workbook, keep sending data to a range of this book every second). Some part of the code is as follows:

/********************************************/
if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Couldn't start Excel and get an application 0bject");
return;
}
app.SetVisible(TRUE);

lpDisp = app.GetWorkbooks(); // Get an IDispatch pointer.
ASSERT(lpDisp);
books.AttachDispatch( lpDisp ); // Attach the IDispatch pointer

// Open a workbook.
lpDisp = books.Open("c:\\Data\\test.xls",
covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional, covOptional, covOptional);
ASSERT(lpDisp);

// Attach to a Workbook object.
book.AttachDispatch( lpDisp ); // Attach the IDispatch pointer

// Get sheets.
lpDisp = book.GetSheets();
ASSERT(lpDisp);
sheets.AttachDispatch(lpDisp);

lpDisp = sheets.GetItem( COleVariant((short)(1)) );
ASSERT(lpDisp);

// Attach the lpDisp pointer to a Worksheet object.
sheet.AttachDispatch(lpDisp);

lpDisp = sheet.GetRange(COleVariant("A2"), COleVariant("A2"));
ASSERT(lpDisp);
range1.AttachDispatch(lpDisp); // Attach the IDispatch pointer
// to the range object.

range1.Clear();
range1.SetValue (COleVariant("test"));

/*********************************************/


The code works well if I didn't touch the excel workbook. However, when I try to edit a cell ( e.g. type just "111" in any cell), something happens: the cpu reaches 100%, Excel froze, and after a while crashes).

After I check it, I found that it may be because when I edit a cell in a workbook, the excel application is set as edit mode and then can't accept any other input data(locked ?). However, my c++ code didn't realize it and keeps sending messages. Thus, the cpu got busy and excel application become crashed. This is my thinking. Gurus, maybe you have other ideas on the real reason ?

If my guess is correct, I plan to find some API for the automation, for instance, getmode of the workbook. If the mode is editing, I will not send message to it. However, although I spent hours finding info about it, I didn't get any cues. Gurus, do you have any ideas whether I can retrieve the status/mode of the excel workbook ? If can, how can I do it ? What function should I call ? Or if my method is not right, could you give me some suggestions on how to get through it.

Thank your guys so much !

Tony
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 12:00 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.