Auto fit Cells in Excel

VJR

Well-Known Member
Staff member
#2
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
 
#3
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.
 
#4
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
#5
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
Staff member
#6
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
#11
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

#12
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