#183924 - 2007-12-19 10:40 AM
Re: Copy an Excel worksheet to an existing workbook
[Re: Allen]
|
YaleCoder
Getting the hang of it
Registered: 2001-12-18
Posts: 61
Loc: Jelenia Gora, Poland
|
OK. So I was able to get it working using VBScript.
BEGIN CODE: Dim wbSource, wbTarget, xlApp, srcWorksheet, tgtWorksheet Set xlApp = CreateObject("Excel.Application") Set wbTarget = xlApp.Workbooks.Open("c:\temp\xl\target.xls") Set wbSource = xlApp.Workbooks.Open("c:\temp\xl\source.xls") Set srcWorksheet = wbSource.Worksheets(1) Set tgtWorksheet = wbTarget.Worksheets(2) srcWorksheet.Copy , tgtWorksheet wbSource.Close True wbTarget.Close True Set wbSource = Nothing Set wbTarget = Nothing Set srcWorksheet = Nothing Set tgtWorksheet = Nothing Set xlApp = Nothing END CODE
This will work for me if I dynamically re-write the value for 'wbTarget ' based on filenames specified by my kix script. I have a huge number of files to modify and this method is rather slow (about 2 seconds per file * 5000+ files). I can't seem to figure out how to convert the above VB syntax to Kix and Google as I may, I can't seem to find anyone else who has done it either. If anyone can point me in the right direction for rewriting this functionality in Kix, it would be greatly appreciated.
_________________________
"When fascism comes to America, it will be wrapped in the flag, carrying a cross." Sinclair Lewis
|
|
Top
|
|
|
|
#184391 - 2008-01-03 03:34 PM
Re: Copy an Excel worksheet to an existing workbook
[Re: Björn]
|
BradV
Seasoned Scripter
  
Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
|
YaleCoder,
If you have 5000+ files to do, you might want to create an ini file and get your source and target data from that. That is, set keys such as:
[Data]
number = 5012
source1 = ...
target1 = ...
source2 = ...
target2 = ...
Then, you can just loop through the ini (or set a key with the total number of targets). User readprofilestring and you can let it run overnight or over the weekend. 
Regards,
Brad V
|
|
Top
|
|
|
|
#184410 - 2008-01-04 09:38 AM
Re: Copy an Excel worksheet to an existing workbook
[Re: BradV]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
Dim $wbSource, $wbTarget, $xlApp, $srcWorksheet, $tgtWorksheet
$xlApp = CreateObject("Excel.Application")
$wbTarget = $xlApp.Workbooks.Open("c:\temp\xl\target.xls")
$wbSource = $xlApp.Workbooks.Open("c:\temp\xl\source.xls")
$srcWorksheet = $wbSource.Worksheets(1)
$tgtWorksheet = $wbTarget.Worksheets(2)
$srcWorksheet.Copy(, $tgtWorksheet)
$wbSource.Close(1) ;Although I think .Close will do
$wbTarget.Close(1)
$wbSource = ""
$wbTarget = ""
$srcWorksheet = ""
$tgtWorksheet = ""
$xlApp = ""
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|