Format Column Excel

Hi Guys!

I am working on excel, the user enter some data then the robot process that data, the problem is that sometimes the user change the wide column for example and that data is show like ######## so when the robot go to read the data read that ######## .

Can I set the column wide before read the data in excel? if is possible could you give me some advice how or were to find that information.

thanks in advance

@carmen, ensure that the PreserveFormat property is checked on the read range and try again.

Optionally, use invoke VBA and run one of these VBA methods: Worksheets("Sheet1").Range("A1:E1").Columns.AutoFit
Worksheets("Sheet1").Columns("A:I").AutoFit

https://docs.microsoft.com/en-us/office/vba/api/excel.range.autofit

thanks, PreserveFormat works, I will ask to the user not change the excel format.

I am trying to use the invoke VBA, I think that will be a better solution.
I downloaded one example … but I have not strong code background so not sure what to do, I am just trying …if you have any hint I will appreciate.

thanks

@carmen, I have never used the activities either, but something to note: Make sure the excel file is macro enabled, you can do this by: opening the excel workbook, Click File —> Options --> Trust Center --> Trust center settings --> check the box (under the policy tips)

Optionally, just write your function on the excel file itself, this will work automatically, no matter what the user does on the file, the macro will force all columns to autofit. See example below:

ok I will check that option, thanks

@carmen, you did mention that PreserveFormat worked, so dont forget to mark my post as a solution, i can still help you further but make sure you do that so the answer that solves this problem shows up first when other people search for the solution to the same problem.

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