PxPlus User Forum

Main Board => Discussions => Programming => Topic started by: JuanVelazquez on October 28, 2019, 08:51:50 AM

Title: Copy or duplicate excel sheet
Post by: JuanVelazquez on October 28, 2019, 08:51:50 AM
Good morning

I have an excel book which is composed of several sheets. Currently I have the need to copy or duplicate one of the sheets within the same book but I have not got the form.

The syntax used in VB is:
Worksheets ("Source"). Copy After: = Worksheets ("Final")

Where "Origin" is the sheet to be copied and will be located after the "Final" sheet.

So far I have not been able to properly use the Copy property.

I currently use the object:
DEF OBJECT ex, "excel.application"

Thank you very much for the help you can give me.

Regards
Title: Re: Copy or duplicate excel sheet
Post by: koenv on October 28, 2019, 10:10:58 AM
->def object excel,"Excel.Application"
->workbook=excel'workbooks'open("filename.xlsx")
->workbook'worksheets("Origin")'copy(*,*workbook'worksheets("Final"))
->excel'visible=1

By default you'll end up with a new worksheet named "Origin (2)".
Title: Re: Copy or duplicate excel sheet
Post by: JuanVelazquez on October 28, 2019, 10:29:25 AM
->def object excel,"Excel.Application"
->workbook=excel'workbooks'open("filename.xlsx")
->workbook'worksheets("Origin")'copy(*,*workbook'worksheets("Final"))
->excel'visible=1

By default you'll end up with a new worksheet named "Origin (2)".

Hi Koenv

Thanks for the help, it worked perfectly

Regards