+ Reply to Thread
Results 1 to 4 of 4

Macro to Autofit Columns of CSV Files in a folder

  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Macro to Autofit Columns of CSV Files in a folder

    I have tried to write code to autofit Cols A to D of all csv files in folder C:\Journals, but cannot get this to work


    Please Login or Register  to view this content.
    It would be appreciated if someone could kindly amend my code
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    03-24-2020
    Location
    Thailand
    MS-Off Ver
    Office 2016
    Posts
    897

    Re: Macro to Autofit Columns of CSV Files in a folder

    To the best of my knowledge: You can't retain formatting such as column widths in a CSV file.

    So the code may well does work, but when saving the CSV file and closing it, the column widths are lost again.
    Try manually to change the column width, then save the CDV file and close it. Re-open the file. Columns will be back to default.

    You could open the CSV files, autofit, then save as excel files if that does not cause other issues on how you need to work with these files.
    If your Question is answered; please mark it SOLVED. If you are happy with a member's solution, say 'Thanks' and click the 'Star' to Add Reputation.

  3. #3
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Macro to Autofit Columns of CSV Files in a folder

    Thanks for the feedback. The column width on the source sheets in Excel are fine but the sheets are exported as CSV files to be uploaded into an accounting software package that will only accept CSV files

    At least now I know that the column width in a CSV file will always default to the specified CSV setting for col width

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Macro to Autofit Columns of CSV Files in a folder


    Again, column width does not exist within a csv file as it is nothing but a delimited text file !

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copy specific columns from multiple files in folder and combine those columns in workbook
    By JaffarAhamed in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 09-13-2023, 04:11 AM
  2. [SOLVED] List Files in a Folder Macro detects an Invisible File not existing in the Folder Issue
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-06-2022, 03:49 AM
  3. [SOLVED] Macro to copy .xlsm files in folder and sub-folder to foldr C:\old pull files
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-15-2021, 09:55 PM
  4. [SOLVED] Macro to list and open .xlsm files in folder and sub-folder
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-24-2019, 07:35 PM
  5. AutoFit columns with macro
    By deano3141 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-14-2014, 08:58 AM
  6. Macro to create a folder and then save all files in that folder
    By gokzee in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-27-2013, 01:49 PM
  7. Replies: 1
    Last Post: 03-12-2013, 04:45 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1