I'm trying to refine the below code /commented out/ to something like the shorter script at the bottom.
Using VBA6 as this is legacy code.
Private Sub XLSetCol(xc1, xc2, xc3, xc4, xc5, xc6, xc7, xc8, xc9, xc10, xc11, xc12, xc13, xc14, xc15)
' Column Width
'excel_app.Columns("A").ColumnWidth = xc1
' excel_app.Columns("B").ColumnWidth = xc2
' excel_app.Columns("C").ColumnWidth = xc3
' excel_app.Columns("D").ColumnWidth = xc4
' excel_app.Columns("E").ColumnWidth = xc5
' excel_app.Columns("F").ColumnWidth = xc6
' excel_app.Columns("G").ColumnWidth = xc7
' excel_app.Columns("H").ColumnWidth = xc8
' excel_app.Columns("I").ColumnWidth = xc9
' excel_app.Columns("J").ColumnWidth = xc10
' excel_app.Columns("K").ColumnWidth = xc11
' excel_app.Columns("L").ColumnWidth = xc12
' excel_app.Columns("M").ColumnWidth = xc13
' excel_app.Columns("N").ColumnWidth = xc14
' excel_app.Columns("O").ColumnWidth = xc15
The below code results in
"Runtime error '1004' Unable to set the ColumnWidth property of the Range Class.
For temp = 1 To 15
tempa = "ABCDEFGHIJKLMNO"
middle = Mid(tempa, temp, 1)
foo = ("xc" & temp)
excel_app.Columns(middle).ColumnWidth = foo
Next temp
End Sub