Copy Complete sheet op excel to another workbook

Post Reply
Marc Vanzegbroeck
Posts: 1163
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Copy Complete sheet op excel to another workbook

Post by Marc Vanzegbroeck »

Hi,

I want to open 2 excel-files, and want to copy a complete worksheet to the other excel-file.
How can I do this?

One excel is object oExcel, the other oExcelInput
with this code I can copy it

Code: Select all | Expand


      oExcelInput:Sheets(oExcelInput:Worksheets( 'Network' ):name):Select()
      oExcelInput:Sheets(oExcelInput:Worksheets( 'Network' ):name):copy()
 


but how add it to the other workbook?
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
Posts: 1163
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Re: Copy Complete sheet op excel to another workbook

Post by Marc Vanzegbroeck »

Hi,

In VBA it's like this

Code: Select all | Expand

Sheets("Network").Copy Before:=Workbooks("Map19").Sheets(3)


How can I convert it to FWH?
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
User avatar
Enrico Maria Giordano
Posts: 8767
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 5 times
Contact:

Re: Copy Complete sheet op excel to another workbook

Post by Enrico Maria Giordano »

Try something like this:

Code: Select all | Expand

oExcelInput:Sheets( "Network" ):Copy( oExcel:Sheets( 3 ) )


EMG
Marc Vanzegbroeck
Posts: 1163
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Re: Copy Complete sheet op excel to another workbook

Post by Marc Vanzegbroeck »

Thank you,

Unfortunately I get an error:

    Error description: Error Excel.Application:SHEETS/16389 E_FAIL: COPY
    Args:
    [ 1] = O Object


Enrico Maria Giordano wrote:Try something like this:

Code: Select all | Expand

oExcelInput:Sheets( "Network" ):Copy( oExcel:Sheets( 3 ) )


EMG
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
User avatar
Enrico Maria Giordano
Posts: 8767
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 5 times
Contact:

Re: Copy Complete sheet op excel to another workbook

Post by Enrico Maria Giordano »

Does exist the Sheet number 3 in oExcel? The first is 0, if I remember correctly.

EMG
Marc Vanzegbroeck
Posts: 1163
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Re: Copy Complete sheet op excel to another workbook

Post by Marc Vanzegbroeck »

There are 4 Sheets.

I allready tried with 0 and 1, but the same error.

Enrico Maria Giordano wrote:Does exist the Sheet number 3 in oExcel? The first is 0, if I remember correctly.

EMG
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
User avatar
Enrico Maria Giordano
Posts: 8767
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 5 times
Contact:

Re: Copy Complete sheet op excel to another workbook

Post by Enrico Maria Giordano »

Can you send to my email all the required files (a simple prg and the two xls) to make a test here?

EMG
User avatar
alerchster
Posts: 97
Joined: Mon Oct 22, 2012 4:43 pm
Has thanked: 2 times

Re: Copy Complete sheet op excel to another workbook

Post by alerchster »

Try

Code below copy sheet network from workbook network to workbook map19 as sheet network (sheet on 3rd position)

Code: Select all | Expand


...
function excel()
   local oExcel := CreateObject( "excel.application" )
   local oBook1  := oExcel:workbooks:Open("network.xlsx")
   local oBook2  := oExcel:workbooks:Open("map19.xlsx")

   oExcel:Visible = .T.
   
   oBook1:Sheets("Network"):Copy(oBook2:Sheets(3))
 
return nil
 
Regards

Ing. Anton Lerchster
Marc Vanzegbroeck
Posts: 1163
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Re: Copy Complete sheet op excel to another workbook

Post by Marc Vanzegbroeck »

Anton,

Thank you. It's working very nice.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
Posts: 1163
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Re: Copy Complete sheet op excel to another workbook

Post by Marc Vanzegbroeck »

Anton,

Thank you. It's working very nice.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Post Reply