How to move excel sheet at the end using VBA script/code

Below is the one line code i have written to move sheet named ‘Final’ at the end,

Getting this error

Kindly help if i need to pass something in the Edit arguments tab. Thank you

Hi @Nishant_mantri

Check out this link

https://www.extendoffice.com/documents/excel/3155-excel-move-sheet-to-end-front.html

Chout this docs

https://docs.uipath.com/activities/other/latest/workflow/invoke-vb-script

Regards
Gokul

Hi @Nishant_mantri

Have passed the input arguments correctly?

Regards
Sudharsan

what exactly do i need to pass in Invoked code argument? Name: Worksheets? what should be the Type and value?

I did go through this… got the vba code from the first link, but not able to understand how to use the same in Invoke VBA code activity…

Hi Sudharshan,
Any help on this? thank you

@rodrigo.simao Hi Rodrigo… any help on this?

Hi @Nishant_mantri

Have you tried with macro

Hello @Nishant_mantri, I’m currently trying to figure it out…

@Nishant_mantri
try this

Sub MoveWorksheet()
Worksheets(“final”).Move After:=Worksheets(Worksheets.Count)
End Sub

refer this

that is just the VBA code to move the sheet to the end, i need to use that in the Invoke code activity in UiPath… not able to do it… I did go through the link which you have posted, there is no solution in that…

@Nishant_mantri

You can also use macros, Try like this

Here is the script
MoveSheet.vb (202 Bytes)

Make sure that this option is enabled

Regards
Sudharsan

1 Like

Hi @Nishant_mantri

You can try this xaml by using Invoke Code

BlankProcess13.zip (44.1 KB)

im getting this error in the Entry Method parameters property

@Nishant_mantri

Try this by using Invoke Code activity

@Nishant_mantri

You can try this way also by using Excel Invoke VBA activity

Code:

Sub MoveSheetToEnd()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("Sheet3") ' Replace "SheetName" with the name of the sheet you want to move
    
    ' Move the sheet to the end
    ws.Move After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
End Sub

BlankProcess13.zip (51.8 KB)

Works perfect… Thanks a lot…

However, if my workbook is already opened what changes I need to make to the code, I think i need to set work book to Activeworkbook, i tried but i think my syntax is incorrect, getting exception for the same.

@Nishant_mantri

Try this

Sub MoveSheetToEnd()
    Dim ws As Worksheet
    Dim activeWorkbook As Workbook

    ' Set the active workbook
    Set activeWorkbook = ActiveWorkbook

    ' Replace "SheetName" with the name of the sheet you want to move
    Set ws = activeWorkbook.Sheets("SheetName")

    ' Move the sheet to the end
    ws.Move After:=activeWorkbook.Sheets(activeWorkbook.Sheets.Count)
End Sub

Perfect… no need to open workbook as this is inside use excel scope… Thank you Irtetala

1 Like

Hope it’s clarified @Nishant_mantri

If yes would suggest to close this topic