Invoke code to move worksheets

hi community,

I am finding a way to move the worksheets from one workbook to another one.

I found a vba coding but i am not allowed to use vba

therefore could share some coding for me?

Thanks.

@raymondhui

  1. Use Read Range activity to read it from one excel file and it will give output as DataTable. Let’s say ‘InputDT’.

  2. And then use Write Range activity and pass inputDT to write into other excel file.

Hi,

We can achieve it using ClosedXML (used from Excel.Activities Package), as the following.

wbSrc = New ClosedXML.Excel.XLWorkbook("src.xlsx")
wbDist = New ClosedXML.Excel.XLWorkbook("dist.xlsx")
ws1 = wbSrc.Worksheet("Sheet1")
ws1.CopyTo(wbDist,"NewSheetName")
ws1.Delete()
wbDist.Save()
wbSrc.Save()

note: wbSrc and wbDist is XLWorkbook type. ws1 is IXLworkSheet type.

Regards,

as there are many formatting in the worksheet, therefore cant use read range?

Hi

Did we try with activity

Cheers @raymondhui

Hey @raymondhui

Check this thread from stack overflow: C# - How to copy a single Excel worksheet from one workbook to another? - Stack Overflow

It’s the C# code but we can try to replicate the same in UiPath Invoke Code

Check if this helps you

Hey @raymondhui

PFA solution workflow for your question

Forum_Solutions.zip (15.2 KB)

Cheers,
Parth

1 Like

yea finally i do more steps and use this activity.

1 Like

Glad
Happy automation @raymondhui

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.