Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Working with Excel 2003 from a Visual C++ program

I am quite new to programming. Despite that I have to write a C++ program
that opens an .xls workbook, selects a specified worksheet and puts data in
specified cells of the worksheet. I have found a document in the Internet
that describes how to use the Excel COM model. Based on this I created a
program that is able o open a specified .xls workbook and put data in
specified cells in the active sheet. However I do not know how to select a
specified worksheet so that I do not put the data in the worksheet that ust
happens to be active when opening the workbook. How to do that?

Here is the code that does what I described:

CoInitialize(NULL);
Excel::_ApplicationPtr xl;
xl.CreateInstance(L"Excel.Application");
xl-Visible = true;
xl-Workbooks-Open(L"C:\\Documents and Settings\\WRO00724\\my
documents\\Visual Studio
2008\\Projects\\Project1\\Excel3\\Excel3\\Example. xls");
Excel::_WorksheetPtr pSheet = xl-ActiveSheet;
Excel::RangePtr pRange = pSheet-Cells;
pRange-Item[2][1] = 0.86;
pRange-Item[3][1] = "test";

What program lines should I include in order to be able to specify the
particular worksheet the data have to go to?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Working with Excel 2003 from a Visual C++ program


I have finally found a solution:

Excel::_WorksheetPtr myWrks(xl-Worksheets-Item["Sheet2"]);
myWrks-Activate();


So my program looks now this way:

CoInitialize(NULL);
Excel::_ApplicationPtr xl;
xl.CreateInstance(L"Excel.Application");
xl-Visible = true;
xl-Workbooks-Open(L"C:\\Documents and Settings\\WRO00724\\my
documents\\Visual Studio
2008\\Projects\\Project1\\Excel3\\Excel3\\Example. xls");
Excel::_WorksheetPtr myWrks(xl-Worksheets-Item["Sheet2"]);
myWrks-Activate();
Excel::_WorksheetPtr pSheet = xl-ActiveSheet;
Excel::RangePtr pRange = pSheet-Cells;
pRange-Item[2][1] = 0.86;
pRange-Item[3][1] = "test";



"zm01" wrote:

I am quite new to programming. Despite that I have to write a C++ program
that opens an .xls workbook, selects a specified worksheet and puts data in
specified cells of the worksheet. I have found a document in the Internet
that describes how to use the Excel COM model. Based on this I created a
program that is able o open a specified .xls workbook and put data in
specified cells in the active sheet. However I do not know how to select a
specified worksheet so that I do not put the data in the worksheet that ust
happens to be active when opening the workbook. How to do that?

Here is the code that does what I described:

CoInitialize(NULL);
Excel::_ApplicationPtr xl;
xl.CreateInstance(L"Excel.Application");
xl-Visible = true;
xl-Workbooks-Open(L"C:\\Documents and Settings\\WRO00724\\my
documents\\Visual Studio
2008\\Projects\\Project1\\Excel3\\Excel3\\Example. xls");
Excel::_WorksheetPtr pSheet = xl-ActiveSheet;
Excel::RangePtr pRange = pSheet-Cells;
pRange-Item[2][1] = 0.86;
pRange-Item[3][1] = "test";

What program lines should I include in order to be able to specify the
particular worksheet the data have to go to?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to unload the loaded XLL file in Excel? Hi all, I amdebugging XLL link library using Visual C++. Everytime I rebuild the XLL, Ihave to close the whole Excel program and relaunch the Excel program again,and then load in the newly gene LunaMoon Excel Discussion (Misc queries) 0 July 28th 08 11:03 PM
Why Excel 2003 VBA program not working in Excel 2007? James Heywood Excel Programming 2 July 7th 08 01:43 PM
changing the visual basic in office 2003 to visual studio net bigdaddy3 Excel Discussion (Misc queries) 1 September 13th 05 10:57 AM
Excel 2003 Database Driver Visual FoxPro 7 on Server 2003. Cindy Winegarden Excel Discussion (Misc queries) 0 November 28th 04 12:07 AM


All times are GMT +1. The time now is 08:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"