How to delete pages in word document using UiPath

Hi. I have word documents containing multiple pages. I need to delete selected pages from each of those documents. Any ideas how to proceed using UiPath?

Below macro code is working fine when running it from word document correctly.

Sub DeletePagesInWord()
Dim iRange As Range
Dim iPage As String
Dim iDoc As Document
Dim iPageCount As Integer
Dim iArr
Dim I, xSplitCount As Long
Application.ScreenUpdating = False
Set iDoc = ActiveDocument
iPage = InputBox(“Enter the page numbers of pages to deleted: " & vbNewLine & vbNewLine & _
“NOTE: Use comma to separate page numbers”, “Delete Pages”, “”)
iArr = Split(iPage, “,”)
iPageCount = UBound(iArr)
For I = iPageCount To 0 Step -1
Selection.GoTo wdGoToPage, wdGoToAbsolute, iArr(I)
iDoc.Bookmarks(”\Page").Range.Delete
Next
Application.ScreenUpdating = True
End Sub

But, when I made changes to above code to pass the page numbers as Parameters from UiPath it is behaving differently (Macro with Parameters)

Sub DeletePagesInWord(iPage As String)
Dim iRange As Range
Dim iDoc As Document
Dim iPageCount As Integer
Dim iArr
Dim I, xSplitCount As Long
Application.ScreenUpdating = False
Set iDoc = ActiveDocument
iArr = Split(iPage, “,”)
iPageCount = UBound(iArr)
For I = iPageCount To 0 Step -1
Selection.GoTo wdGoToPage, wdGoToAbsolute, iArr(I)
iDoc.Bookmarks("\Page").Range.Delete
Next
Application.ScreenUpdating = True
End Sub

@Subhash_B What was the Error you received ?

Other pages along with the ones mentioned in parameter are also getting deleted

@Subhash_B Can you show me the Screenshots of your workflow or send the Workflow so that we can analyse it? Also How are you passing the Input Page numbers to be deleted ?

I do think that the For Loop Introduced may not be working as expected.

I am using custom word activities package (by BalaRev) to execute word macros here. Attaching word scope with execute macro activity (screenshot 1) and screenshot 2 has parameter passing as 1-dimentional array

PS: Attaching screenshots in 2 posts due to forum restrictions

Screen 2