AutoFit Column in Excel

Hi all

Is there any activity that u can setting some column width and else?


If you have Excel installed you can use an Invoke VBA activity with this script:

Function AutoFitColumns(sheetName As String) As String
' AutoFits column widths for all used columns on the specified sheet
    On Error GoTo ErrorHandler
    With Sheets(sheetName)
    End With
    AutoFitColumns = "Success"
    Exit Function
    Debug.Print Err.Description
    AutoFitColumns = "Error: " & Err.Description
End Function

Save the script in a text file in your project structure. Call the function like this:


Pass your sheet name through EntryMethodParameters like so:


hi @moosh

ok thanks for the feedback,.will test it


1 Like

Also, if you’ve never done it before you may need to enable programmatic access, otherwise you’ll probably get an error.

To do this:

  1. Open Excel and go into File > Options
  2. Click the Trust Centre tab
  3. Click Trust Centre Settings…
  4. Click the Macro Settings tab
  5. Check the box for Trust access to the VBA project object model
  6. Click OK

You should only need to do this once.