Create fixed length AIX word pad file

Posted on 2011-05-04
Last Modified: 2012-05-11
I have an xL file that i need to convert into a fixed length AIX file in xL or Word Pad.
example below:
3M 021200-43178      6
3M 021200-71120      32
3M 048011-04028      55
3M 048011-04029      116
3M 051115-26230      296
3M 051131-52750      6
Below are the parameters:
Field                      Start Position                 Length           Format
Item Code                1                                  26               Character
Quantity                 28                                 11                Decimal 99999999.99
Question by:Mikethiergartner
    LVL 22

    Accepted Solution

    I think this macro is pretty close to what you need:
    Option Explicit
    Sub SaveAsText()
        Dim rw As Range
        Dim lngFile As Long
        Dim strLine As String
        lngFile = FreeFile
        Open ActiveWorkbook.FullName & ".txt" For Output Access Write Shared As #lngFile
        For Each rw In ActiveSheet.UsedRange.Rows
            strLine = Left(rw.Cells(1, 1).Value & String(26, " "), 26)
            strLine = strLine & rw.Cells(1, 2).Value
            Print #lngFile, strLine
        Close #lngFile
    End Sub

    Open in new window

    It creates a file with same name as the .xls but with the extension .txt.
    LVL 24

    Expert Comment

    This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
    How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
    This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
    This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now