+ Reply to Thread
Results 1 to 4 of 4

Saving xls file as fixed width

  1. #1
    Registered User
    Join Date
    02-22-2010
    Location
    Edinburgh
    MS-Off Ver
    Excel 2003
    Posts
    2

    Saving xls file as fixed width

    I am trying to created test data files. The data is currently in Excel and the widths of the columns have been set to that of the fields within a database. I want to save the Excel file so that the widths of the columns remain. I have tried saving as .prn and this works for some files however .prn is limited to 240 characters per line so any files which have more than this automatically wrap the columns. This is no good as when the file is read the columns are counted therefore the load gets confused.
    I have tried saving as .csv and getting rid of the commas however this does not save the column widths.

    How can I save the file so that the widths are saved to some sort of text file?
    Other info - ultimately I need to change the file so that it is .dat and this is simple enough by changing the file extension.


    Thanks in advance

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Saving xls file as fixed width

    Given the usual way of setting column widths and saving to prn does not work you will have to use VBA to write the file.
    Last edited by Andy Pope; 02-22-2010 at 07:50 AM. Reason: fix link
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Saving xls file as fixed width

    Given the usual way of setting column widths and saving to prn does not work you will have to use VBA to wrhttp://www.exceltip.com/exceltips.phpite the file.

    Here is some code to get you started.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-22-2010
    Location
    Edinburgh
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Saving xls file as fixed width

    Thanks for your suggestion Andy. I managed to find a simple macro, details below, yesterday which worked a treat after I edited it to suit my data.

    Thanks again,
    Lisa

    https://www.blogger.com/comment.g?bl...12465133508496

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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