Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default copy range from one excel sheet to other fails.

Guys

I need to copy data from an uploaded excel into master excel . I'm
doing
this but the excel objects are not getting cleaned up. I see 2
instances of
Excel running in 'Task Manager'. Whats the best way to copy range of
data
from one excel workbook to other workbook. HEre is my code;

Excel.Application srcExcel = new Excel.ApplicationClass();
Excel._Workbook srcWb = srcExcel.Workbooks.Open(fName, Missing.Value,
Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value);
Excel._Worksheet srcWsh = (Excel._Worksheet)srcWb.Sheets.get_Item(2);

Excel.Application dstExcel = new Excel.ApplicationClass();
Excel._Workbook dstWb = dstExcel.Workbooks.Open(eventdir,
Missing.Value,
Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value);
Excel._Worksheet dstWsh = (Excel._Worksheet)dstWb.Sheets.get_Item(2);

// following seems to work but excel objects are not getting cleaned up
((Excel.Range)dstWsh.get_Range("C4", "N26")).Value2
=
((Excel.Range)srcWsh.get_Range("C4",
"N26")).Value2;

// this one gives error.
//Excel.Range r1 = (Excel.Range)srcWsh.get_Range("C4:N26",
Type.Missing);
//Excel.Range r2 = (Excel.Range)dstWsh.get_Range("C4:N26",
Type.Missing);
//r2.Value2 = r1.Value2;
//r1.Copy(r2);

pl help.

thanks

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
Excel 2002 SP3 Copy Worksheet with another sheet named range now # Brewmanz Excel Discussion (Misc queries) 0 October 1st 09 12:35 AM
Excel VBA Paste of Range with PrefixCharacter fails from VB.NET Nicholas Dreyer Excel Discussion (Misc queries) 0 April 6th 07 04:09 AM
How do I edit a selected range then copy the range into an new sheet??? dwyborn Excel Programming 2 December 16th 05 04:11 PM
sheet copy method fails... mark Excel Programming 2 November 4th 05 02:41 AM
Copy to another sheet fails Ole[_4_] Excel Programming 1 March 24th 05 09:14 PM


All times are GMT +1. The time now is 10:04 PM.

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

About Us

"It's about Microsoft Excel"