Auto fit Cells in Excel

VJR

Well-Known Member
Hello vinay,

To Format a cell you will need to use the 'Format Cell' action of the MS Excel VBO. There is an Input parameter called 'Cell Format'
Not sure if there is a direct way to AutoFit cells. You may try the below options-
- Write a macro that will AutoFit those columns and then use the 'Run Macro' action of the MS Excel VBO
- Or write your own VBO by researching on how to use the Excel Object Model to use the AutoFit while creating a VBO.


~VJ
 
Hi @vinay

As VJR said, using macros is the easiest option to format the Excel workbook.
I've written a macro and you can use it to resize your excel worksheet.

Sub resize()
' resize Macro
Range("B12").Select
Columns("B:B").EntireColumn.AutoFit
End Sub

Just edit the Column B:B to A:A or C:C according to the column you want to resize or Autofit.

Then using the MS Excel VBO "Run Macro" you can use this macro in your BluePrism object.
Let me know if you have any further questions.
 

vinay

Member
Hi @vinay

As VJR said, using macros is the easiest option to format the Excel workbook.
I've written a macro and you can use it to resize your excel worksheet.

Sub resize()
' resize Macro
Range("B12").Select
Columns("B:B").EntireColumn.AutoFit
End Sub

Just edit the Column B:B to A:A or C:C according to the column you want to resize or Autofit.

Then using the MS Excel VBO "Run Macro" you can use this macro in your BluePrism object.
Let me know if you have any further questions.
Thank You Vry Much
 

Shweta

Active Member
Hi,

I used the shared macro and getting error:

"Your expression does not appear to be valid:

Syntax error. The token 'resize' is invalid. Please check the case of your operators (eg 'or' versus 'OR') and check that your functions use brackets after the function name eg Now(), eg Len("abc")."


Can you please suggest me?

Thanks!
 

VJR

Well-Known Member
Hi Shweta,

The error you are seeing does not co-relate to the code in the macro.
Are you able to share the details of the stage that you are receiving this error on with screenshots, properties etc?
 

Shweta

Active Member
Hi VJ,

Sure.

Please find attached the screenshots.

When I am clicking on Evaluate Expression, I am getting error (screenshot - Error.png).

Thanks!
 

Attachments

  • Autofit cell action.PNG
    29.1 KB · Views: 210
  • macro data.PNG
    18.9 KB · Views: 170
  • Error.PNG
    50.1 KB · Views: 144

Shweta

Active Member
Hello,

I wrote the below macro to Autofit the columns.

Sub resize()
' resize Macro
Range("A1").Select
Columns("A:C").EntireColumn.AutoFit
Range("E1").Select
Columns("E:L").EntireColumn.AutoFit

With Worksheets("Sheet1").Columns("D")
.ColumnWidth = .ColumnWidth + 10
End With

End Sub

Range, you can specify as per your requirements.

Then using the MS Excel VBO "Run Macro" I gave this macro in my BluePrism object.

I have attached the Run Macro Action properties for your reference.

Thanks!
 

Attachments

  • Run Macro Action properties.PNG
    28.2 KB · Views: 173

raygan1987

New Member
Hello,

I wrote the below macro to Autofit the columns.

Sub resize()
' resize Macro
Range("A1").Select
Columns("A:C").EntireColumn.AutoFit
Range("E1").Select
Columns("E:L").EntireColumn.AutoFit

With Worksheets("Sheet1").Columns("D")
.ColumnWidth = .ColumnWidth + 10
End With

End Sub

Range, you can specify as per your requirements.

Then using the MS Excel VBO "Run Macro" I gave this macro in my BluePrism object.

I have attached the Run Macro Action properties for your reference.

Thanks!

Thanks Shweta....will try so
 
Top