ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy worksheets in excel automation app using VC7 (https://www.excelbanter.com/excel-programming/368712-copy-worksheets-excel-automation-app-using-vc7.html)

Yannick De Koninck

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




All times are GMT +1. The time now is 09:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com