Macros - Not executing as intended

Hello All,

Just observed a peculiar thing while running macro and wanted to know if anyone could shed light

Scenario :

I have an excel file with data. I am removing the empty rows and columns through uipath and pasting the new data in “Sheet2”. I have a macro which runs on sheet2 and converts the data into “unicode text file”

Problem Statement :

When i run the macro directly from Excel (after creating “sheet2” through uipath), it build a new sheet and does not delete it but creates the text file perfectly.

But when i run this macro through uipath the sheet that is created is deleted and the text file has extra spaces at the end. These spaces are the count of columns deleted.

I want to understand why this is happening. I dont want those extra spaces.
Attaching sample excel file and the macros. You may clean up the macros if need be.

I am attaching the extra spaces screenshot and code as well for reference. Also am running the code on Studio Pro Community Edition.

Create Text File.xaml (20.6 KB)
Sample.xlsx (10.4 KB) New Text Document.txt (1.7 KB)