FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Copy Complete sheet op excel to another workbook
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Copy Complete sheet op excel to another workbook
Posted: Wed Jan 20, 2021 12:31 PM
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 (fw): Select all Collapse
      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
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Copy Complete sheet op excel to another workbook
Posted: Wed Jan 20, 2021 02:25 PM
Hi,

In VBA it's like this
Code (fw): Select all Collapse
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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Copy Complete sheet op excel to another workbook
Posted: Wed Jan 20, 2021 03:27 PM
Try something like this:

Code (fw): Select all Collapse
oExcelInput:Sheets( "Network" ):Copy( oExcel:Sheets( 3 ) )


EMG
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Copy Complete sheet op excel to another workbook
Posted: Wed Jan 20, 2021 03:42 PM
Thank you,

Unfortunately I get an error:

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


    Enrico Maria Giordano wrote:Try something like this:

    Code (fw): Select all Collapse
    oExcelInput:Sheets( "Network" ):Copy( oExcel:Sheets( 3 ) )


    EMG
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Copy Complete sheet op excel to another workbook
Posted: Wed Jan 20, 2021 03:48 PM

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

EMG

Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Copy Complete sheet op excel to another workbook
Posted: Wed Jan 20, 2021 03:56 PM
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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Copy Complete sheet op excel to another workbook
Posted: Wed Jan 20, 2021 04:06 PM

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

EMG

Posts: 137
Joined: Mon Oct 22, 2012 04:43 PM
Re: Copy Complete sheet op excel to another workbook
Posted: Wed Jan 20, 2021 04:17 PM
Try

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

Code (fw): Select all Collapse
...
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
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Copy Complete sheet op excel to another workbook
Posted: Wed Jan 20, 2021 06:12 PM

Anton,

Thank you. It's working very nice.

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Copy Complete sheet op excel to another workbook
Posted: Wed Jan 20, 2021 06:12 PM

Anton,

Thank you. It's working very nice.

Regards,

Marc



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

Continue the discussion