I have the following code to open up a csv file
I am trying to autofit all the columns and then save and close the file
However when opening up the file, the columns are not autofitted to the length of the largest item in each column
Kindly amend my code below so that the columns autofit
I am trying to autofit all the columns and then save and close the file
However when opening up the file, the columns are not autofitted to the length of the largest item in each column
Kindly amend my code below so that the columns autofit
Code:
Sub OpenAndModifyCSVFiles()
Application.ScreenUpdating = False
Dim strFile As String
Dim strFileType As String
Dim strPath As String
Dim lngLoop As Long
Dim LR As Long, i As Long
strPath = "C:\Parts stock"
strFileType = "*.csv" 'Split with semi-colon if you want to specify the file types. Example ->> "*.xls;*.jpeg;*.doc;*.gif"
For lngLoop = LBound(Split(strFileType, ";")) To UBound(Split(strFileType, ";"))
strFile = Dir(strPath & "\" & Split(strFileType, ";")(lngLoop))
Do While strFile <> ""
With Workbooks.Open(strPath & "\" & strFile)
Range("A:R").EntireColumn.AutoFit
End With
ActiveWorkbook.Save
ActiveWorkbook.Close
strFile = Dir
Loop
Next lngLoop
strFile = vbNullString
strFileType = vbNullString
strPath = vbNullString
lngLoop = Empty
End Sub