PC Review


Reply
Thread Tools Rate Thread

Add method of "Sheets" class fails

 
 
=?Utf-8?B?Q29kZUtyYWNrZXI=?=
Guest
Posts: n/a
 
      9th Jul 2007
Hi all,
I am trying to insert a worksheet from one excel workbook to another
excel workbook. The source excel worksheet is of the size 102 MB. So opening
the worksheets in the destination excel workbook and then copying is taking
too much time. So I tried saving the source worksheet as an excel template
(.xlt file) and then tried adding this template to the destination workbook
with the following code :

objExcel = New Excel.Application
objBooks = objExcel.Workbooks
...
objBooks.Open("D:\destExcel.xls")
objBooks.Item(1).Sheets.Add( "D:\sourceExcel.xlt")
....

The Sheets.Add method fails in the above piece of code. Does anybody know
the reason ?
I would also like to know if there is an efficient method of copying a large
sized excel worksheet from one workbook to another without actually having to
open the source worksheet.

Thanks in anticipation,
CodeKracker.
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      9th Jul 2007
I think you are mixing up the Workbooks.Add and Worksheets.Add methods.

Try opening the template file, and copying across that sheet, then close it.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"CodeKracker" <(E-Mail Removed)> wrote in message
news:B29A9D2E-5001-4E17-8576-(E-Mail Removed)...
> Hi all,
> I am trying to insert a worksheet from one excel workbook to
> another
> excel workbook. The source excel worksheet is of the size 102 MB. So
> opening
> the worksheets in the destination excel workbook and then copying is
> taking
> too much time. So I tried saving the source worksheet as an excel template
> (.xlt file) and then tried adding this template to the destination
> workbook
> with the following code :
>
> objExcel = New Excel.Application
> objBooks = objExcel.Workbooks
> ..
> objBooks.Open("D:\destExcel.xls")
> objBooks.Item(1).Sheets.Add( "D:\sourceExcel.xlt")
> ...
>
> The Sheets.Add method fails in the above piece of code. Does anybody know
> the reason ?
> I would also like to know if there is an efficient method of copying a
> large
> sized excel worksheet from one workbook to another without actually having
> to
> open the source worksheet.
>
> Thanks in anticipation,
> CodeKracker.



 
Reply With Quote
 
=?Utf-8?B?TGVu?=
Guest
Posts: n/a
 
      9th Jul 2007
Not very good at Excel, but know Microsoft and their operating system
extremely well. Excel can really take up a lot of system resources. In your
control panel go to System Resources and increase your virtual memory by no
less than 33% of what it currently is. This will definately increase your
overall performance and free up resources that Excel demands!

Sorry I cannot help on the sheets problem, my excel knowledge is very limited!

Good Luck

Len

"CodeKracker" wrote:

> Hi all,
> I am trying to insert a worksheet from one excel workbook to another
> excel workbook. The source excel worksheet is of the size 102 MB. So opening
> the worksheets in the destination excel workbook and then copying is taking
> too much time. So I tried saving the source worksheet as an excel template
> (.xlt file) and then tried adding this template to the destination workbook
> with the following code :
>
> objExcel = New Excel.Application
> objBooks = objExcel.Workbooks
> ..
> objBooks.Open("D:\destExcel.xls")
> objBooks.Item(1).Sheets.Add( "D:\sourceExcel.xlt")
> ...
>
> The Sheets.Add method fails in the above piece of code. Does anybody know
> the reason ?
> I would also like to know if there is an efficient method of copying a large
> sized excel worksheet from one workbook to another without actually having to
> open the source worksheet.
>
> Thanks in anticipation,
> CodeKracker.

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      9th Jul 2007
If you're running this from excel, why create a new instance of excel?

Couldn't you just do:

Dim objBook As Workbook
Set objBook = Workbooks.Open(Filename:="D:\destExcel.xls")
objBook.Sheets.Add Type:="D:\sourceexcel.xlt"

And if you really, really need two instances of excel, I'd use another object
variable that held the workbook that I opened. Then work on that object.





CodeKracker wrote:
>
> Hi all,
> I am trying to insert a worksheet from one excel workbook to another
> excel workbook. The source excel worksheet is of the size 102 MB. So opening
> the worksheets in the destination excel workbook and then copying is taking
> too much time. So I tried saving the source worksheet as an excel template
> (.xlt file) and then tried adding this template to the destination workbook
> with the following code :
>
> objExcel = New Excel.Application
> objBooks = objExcel.Workbooks
> ..
> objBooks.Open("D:\destExcel.xls")
> objBooks.Item(1).Sheets.Add( "D:\sourceExcel.xlt")
> ...
>
> The Sheets.Add method fails in the above piece of code. Does anybody know
> the reason ?
> I would also like to know if there is an efficient method of copying a large
> sized excel worksheet from one workbook to another without actually having to
> open the source worksheet.
>
> Thanks in anticipation,
> CodeKracker.


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
method "range" of object "_worksheet" fails PBcorn Microsoft Excel Programming 5 27th Oct 2008 04:33 PM
Find method fails in Excel 2003 ("Subscript out of range") Guy Jara Microsoft Excel Programming 1 21st Apr 2006 05:01 AM
"PropertyItems" of class Metafile fails with error "Not implemente =?Utf-8?B?UGV0ZXJ2?= Microsoft Dot NET Framework 0 7th Apr 2005 06:01 PM
<FORM METHOD="post" onSubmit="return fieldcheck()" name="orientation" action="http://ws-kitty.BU.edu/AT/survey/orientation/script/write.asp" language="JavaScript"> Joeyej Microsoft ASP .NET 0 4th Jun 2004 08:55 PM
Howto customize "Add Method" wizard on "Add Method" menu of Class View? Bill Smarty Microsoft Dot NET Framework 0 13th Jan 2004 06:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:58 PM.