Consulting

Results 1 to 5 of 5

Thread: VBA - Flat Text Import Changes

  1. #1

    VBA - Flat Text Import Changes

    We have a mission critical spreadsheet that imports a lot of flat text from a desgin program and then brings it in to this spreadsheet.
    We recently updated the design software, which we do once a year and have done so in my 12 years here. This year, they made a change to a file where it placed the header of a column of text in a different place. Now, our program will not import it correctly. It is the PART column...
    Old text file:

    part_01.jpg

    New Text File:
    part_02.jpg


    So as you can see, they moved PART to the lower left.
    Not being an expert in VBA, I am struggling to find exactly where I need to modify the code to bring it in properly..
    This is the section of VBA code where I do think the selections are made but nothing specifies PART in the code...perhaps it is part of the Array? The file is called CZE_DET.OUT.
    SubIMPORT_CZEOUT()
    Dim aryJobs() As String
    Dim strComb As String
    Dim strDir As String
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Sheets("CEE ORDER").Visible = True
    Sheets("CZE_DET").Visible = True
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    Sheets("CEE ORDER").Select
    For i = 1 To colAllBuildings.Count
         strDir = Dir$(colAllBuildings.Item(i) & "\CZE_DET.OUT")
         If strDir <> "" Then
             Workbooks.OpenText Filename:=colAllBuildings.Item(i) & "\CZE_DET.OUT", Origin:=xlWindows, _
             StartRow:=7, DataType:=xlFixedWidth, _
             FieldInfo:=Array(Array(0, 9), Array(5, 1), Array(9, 9), Array(10, 1), _
             Array(13, 9), Array(14, 1), Array(15, 9), Array(16, 1), Array(18, 1), _
             Array(28, 9), Array(35, 9), Array(47, 9), Array(54, 1), Array(57, 1), _
             Array(62, 1), Array(67, 1), Array(72, 1))
             Range("A1:L" & CStr(Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row)).Select
             Selection.Copy
             Windows(strShipperName).Activate ' This line does not work, for NO reason!
    '        Windows(1).ActivatePrevious
             Sheets("CZE_DET").Select
             Range("A1").Select
             If Range("A1").Value <> "" Then
                 ActiveSheet.Range("A65536").End(xlUp).Select
                ActiveCell.Offset(1, 0).Select
             End If
             Selection.PasteSpecial Paste:=xlValues
             Selection.Sort Key1:=Range("A12"), Order1:=xlAscending, Orientation:=xlTopToBottom
             Windows("CZE_DET.OUT").Activate
             ActiveWindow.Close
         End If 
    Next

    Any suggestions?
    Last edited by Aussiebear; 01-18-2023 at 12:28 PM. Reason: Removed additional code tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Can you post an example workbook and text file?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Quote Originally Posted by Bob Phillips View Post
    Can you post an example workbook and text file?
    There are the old and newer CZE_DET.OUT files... https://pinnaclestructures365-my.sha...n6kOg?e=0oyh2k

    The workbook may be harder to post as it attaches an XLA file with the bulk of the VBA code to it from a network share...and the XLA file is protected by a password...so may save it as a different file/name.

  4. #4
    Quote Originally Posted by garak0410 View Post
    There are the old and newer CZE_DET.OUT files... https://pinnaclestructures365-my.sha...n6kOg?e=0oyh2k

    The workbook may be harder to post as it attaches an XLA file with the bulk of the VBA code to it from a network share...and the XLA file is protected by a password...so may save it as a different file/name.
    I tried to remove the password from the XLA file and it wouldn't let me...so I can post modules if needed.

  5. #5
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    From the analysis of the presented code snippet, it seems that the problem should not lie in the CZE_DET.OUT files. The import of the old version as well as the new one runs correctly. The "Part" header is irrelevant here, since the data from the CZE_DET.OUT files are taken from line No. 7, i.e. the header is omitted.
    In the presented code, the following is highlighted:
    Windows(strShipperName).Activate ' This line does not work, for NO reason!
    If, in fact, an error arises on this line then there are two possibilities: either there is no workbook whose name is stored in the strShipperName variable or this workbook is not open. The second possibility is that the window name is not assigned to the strShipperName variable. We should infer that this assignment is in another procedure, which unfortunately we do not see, just as we do not see the assignment to the colAllBuildings collection. Without knowing the rest of the code, it is difficult to answer what should be corrected in the code.

    Artik

Tags for this Thread

Posting Permissions

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