Set Column width in Excel

Hi All,

I am working on a project where i need to adjust columns width based on data present. So, I also implemented below solution which is working without any issues.

Now the problem with this is VBA code is, In VM1 it’s working properly and in VM2 the script is not perfectly adjusting column width. Attaching sample output file generated by VM2.
I have tried using macros also, and i didn’t see any improvement and getting same output file as VBA script in VM2. Please let me know if you identified any issue or solution.

Test file.xlsx (34.3 KB)

Hi @abhilashreddyalla
did any error is thrown while implementing in the VM2?


No, it’s not throwing any error. Both the VBA script & Macro are executing in VM2 and they are not adjusting columns width to 100%.

Hi can u try balareva activity for this ?

Due to restrictions, I am not supposed to install other than UiPath official packages.

Hi @abhilashreddyalla
Can u try below code in invoke code activity [ ]
[Solved] How can I increase the row height of excel row from code? - CodeProject


In my case the column width shouldn’t be a fixed size. It need to adjust based on data available.

I have tried your suggestion and getting below error at Invoke code activity.


Which column in the attached file do you want to adjust the width?
Also, add some data in excel to see the effect.

Save the vba file with .vbs extension

Make sure you have the below settings enabled.

If you still get an error then share the vba code you are using

Hi @Pravin_Patil1 ,

can you try this?

Thank you