Copy worksheets in excel automation app using VC7

Y

Yannick De Koninck

Hello,

I'm doing this automation application that involves copying a sheet from a
specific workbook to another workbook.
I have this code:


CWorkbook WinBook = books.Open(szWorkbook,covOptional, covOptional,
covOptional, covOptional,

covOptional, covOptional, covOptional, covOptional,

covOptional, covOptional, covOptional, covOptional, covOptional, covOptional

);

CWorkbook BRBook = books.Open(szWorkbook2,covOptional, covOptional,
covOptional, covOptional,

covOptional, covOptional, covOptional, covOptional,

covOptional, covOptional, covOptional, covOptional, covOptional, covOptional

);

WBSheets = WinBook.get_Sheets();

BRSheets = BRBook.get_Sheets();

WBsheet = WBSheets.get_Item(COleVariant((short)3));

BRSheet = BRSheets.get_Item(COleVariant((short)1));

CString s1 = CString("[");

s1+= CString(WinBook.get_Name());

s1+= CString("]");

s1+= CString(WBsheet.get_Name());

BRSheet.Copy(covOptional,COleVariant(s1));

...



So this piece of code opens two workbooks: one source (BRBook) and one
destination(WinBook). Takes the sheet to be copied: BRSheet and builds a
string that descibes the sheet after wicht the sourche sheet should be put.

But this code gives me a runtime error message saying the copy method of the
sheets object failed. What am i doing wrong? Thank you very mucht,



Yannick from belgium
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top