View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Yannick De Koninck Yannick De Koninck is offline
external usenet poster
 
Posts: 1
Default Copy worksheets in excel automation app using VC7

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