+ Reply to Thread
Results 1 to 11 of 11

problem in reading new text file in VB script macro

Hybrid View

  1. #1
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,174

    Re: problem in reading new text file in VB script macro

    For the sake of simplicity, I have produced a free-standing conversion in Excel.

    It works in much the same way as your current Excel application.

    However, rather than taking the text file and converting it to Excel, it takes a "new format" text file and converts it to an "old format" text file. This can then be read by the original converter.

    Sub EdiConversion()
    
    Dim TxtFile As Variant
    Dim TxtFileOut As Variant
    Dim EdiRows As String
    Dim Edirow As Variant
    Dim i As Long
    
    ' Ask for the file name that has to be processed
    TxtFile = Application.GetOpenFilename("Text Files (*.txt), *.txt")
    If TxtFile = False Then
        MsgBox "No files selected, nothing to do. Bye."
        Exit Sub
    End If
    
    ' Open the file and read rows processing them one by one
    Open TxtFile For Input Access Read As #1
    TxtFileOut = Left(TxtFile, Len(TxtFile) - 4) & "_OF.txt"
    Open TxtFileOut For Output Access Write As #2
    
    While Not EOF(1)
        Line Input #1, EdiRows
        Edirow = Split(EdiRows, "'")
        For i = LBound(Edirow) To UBound(Edirow)
            If Edirow(i) <> "" Then
                Print #2, Edirow(i) & "'"
           End If
        Next i
    Wend
    
    Close #1
    Close #2
    
    MsgBox "The file has been converted" & vbLf & vbLf & _
           "Input:      " & TxtFile & vbLf & _
           "Output:  " & TxtFileOut & vbLf, , _
           "Edi File Conversion"
    
    End Sub

    It probably wouldn't be too difficult to combine this with the original but I think it's better, at this stage, to "prove the theory" before hacking the original about.

    I trust it will help.

    Regards
    Attached Files Attached Files
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  2. #2
    Registered User
    Join Date
    07-02-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: problem in reading new text file in VB script macro

    Hi,

    The person who created the macro has now left our company, therefore I am ask author to make the changes.

    Yes there will several line items...please see attached example. There can be 100s invoice, container number and amount...

    It would be great if you can create code to convert NEW format into OLD format and this should happen before macro starts reading text file. Is it possible?

    No there are no complex examples...only there can be several line item with the same ID such as RFF+IV, RFF+BM and so on...

    Please help me as I need this macro badly...I would appreciate your help.

    Best Regards,
    Kam.

  3. #3
    Registered User
    Join Date
    07-02-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: problem in reading new text file in VB script macro

    Sorry I didn't see your message and replied by then. Thank you for the below help. It really works...

    Can we add this script into original macro????

    Yes there will several line items...please see attached example. There can be 100s invoice, container number and amount...

    No there are no complex examples...only there can be several line item with the same ID such as RFF+IV, RFF+BM and so on...

    Best Regards,
    Kam.
    Last edited by kamlesh_waghela2000; 01-27-2011 at 08:27 PM.

  4. #4
    Registered User
    Join Date
    07-02-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    9

    Unhappy Re: problem in reading new text file in VB script macro

    Hi, I really appreciate your help on this regard. The macro really works.

    Is it possible to include this new macro into original macro so I don;t have to use two different macros.

    Please advise.

    Thank you in advance.

    Best Regards,
    Kam.

+ 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