Copy Complete sheet op excel to another workbook

Copy Complete sheet op excel to another workbook

Postby Marc Vanzegbroeck » 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: Select all  Expand view  RUN

      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: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Copy Complete sheet op excel to another workbook

Postby Marc Vanzegbroeck » Wed Jan 20, 2021 2:25 pm

Hi,

In VBA it's like this
Code: Select all  Expand view  RUN
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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Copy Complete sheet op excel to another workbook

Postby Enrico Maria Giordano » Wed Jan 20, 2021 3:27 pm

Try something like this:

Code: Select all  Expand view  RUN
oExcelInput:Sheets( "Network" ):Copy( oExcel:Sheets( 3 ) )


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Copy Complete sheet op excel to another workbook

Postby Marc Vanzegbroeck » Wed Jan 20, 2021 3:42 pm

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 view  RUN
oExcelInput:Sheets( "Network" ):Copy( oExcel:Sheets( 3 ) )


EMG
Regards,
Marc

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

Re: Copy Complete sheet op excel to another workbook

Postby Enrico Maria Giordano » Wed Jan 20, 2021 3:48 pm

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Copy Complete sheet op excel to another workbook

Postby Marc Vanzegbroeck » Wed Jan 20, 2021 3: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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Copy Complete sheet op excel to another workbook

Postby Enrico Maria Giordano » Wed Jan 20, 2021 4: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
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Copy Complete sheet op excel to another workbook

Postby alerchster » Wed Jan 20, 2021 4:17 pm

Try

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

Code: Select all  Expand view  RUN

...
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
User avatar
alerchster
 
Posts: 95
Joined: Mon Oct 22, 2012 4:43 pm

Re: Copy Complete sheet op excel to another workbook

Postby Marc Vanzegbroeck » Wed Jan 20, 2021 6:12 pm

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: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Copy Complete sheet op excel to another workbook

Postby Marc Vanzegbroeck » Wed Jan 20, 2021 6:12 pm

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: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 65 guests