Page 1 of 1

Copy Complete sheet op excel to another workbook

Posted: Wed Jan 20, 2021 12:31 pm
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

      oExcelInput:Sheets(oExcelInput:Worksheets( 'Network' ):name):Select()
      oExcelInput:Sheets(oExcelInput:Worksheets( 'Network' ):name):copy()
 
but how add it to the other workbook?

Re: Copy Complete sheet op excel to another workbook

Posted: Wed Jan 20, 2021 2:25 pm
by Marc Vanzegbroeck
Hi,

In VBA it's like this

Code: Select all

Sheets("Network").Copy Before:=Workbooks("Map19").Sheets(3)
How can I convert it to FWH?

Re: Copy Complete sheet op excel to another workbook

Posted: Wed Jan 20, 2021 3:27 pm
by Enrico Maria Giordano
Try something like this:

Code: Select all

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

Re: Copy Complete sheet op excel to another workbook

Posted: Wed Jan 20, 2021 3:42 pm
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

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

Re: Copy Complete sheet op excel to another workbook

Posted: Wed Jan 20, 2021 3:48 pm
by Enrico Maria Giordano
Does exist the Sheet number 3 in oExcel? The first is 0, if I remember correctly.

EMG

Re: Copy Complete sheet op excel to another workbook

Posted: Wed Jan 20, 2021 3:56 pm
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

Re: Copy Complete sheet op excel to another workbook

Posted: Wed Jan 20, 2021 4:06 pm
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

Re: Copy Complete sheet op excel to another workbook

Posted: Wed Jan 20, 2021 4:17 pm
by alerchster
Try

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

Code: Select all

...
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
 

Re: Copy Complete sheet op excel to another workbook

Posted: Wed Jan 20, 2021 6:12 pm
by Marc Vanzegbroeck
Anton,

Thank you. It's working very nice.

Re: Copy Complete sheet op excel to another workbook

Posted: Wed Jan 20, 2021 6:12 pm
by Marc Vanzegbroeck
Anton,

Thank you. It's working very nice.