Consulting

Results 1 to 5 of 5

Thread: Request to Modify Macro

  1. #1

    Request to Modify Macro

    Found this code somewhere. How do I change this so that it runs on ALL text files in Sample folder and instead of debug.print, change so that it outputs to excel sheet column A, starting in A2? Can anyone help?

    Sub ExtractValueBetweenTags()
    
    Dim myFile As String, text As String, textline As String, posLat As Integer, posLong As Integer
    myFile = "E:\Sample\Sample.TXT"
    
    Open myFile For Input As #1
        Do Until EOF(1)
            Line Input #1, textline
            text = text & textline
        Loop
    Close #1
    cellValue = text
    openingParen = InStr(cellValue, "<TAG>")
    closingParen = InStr(cellValue, "</TAG>")
    enclosedValue = Mid(cellValue, openingParen + 5, closingParen - openingParen - 5)
    Debug.Print enclosedValue
    
    End Sub

  2. #2
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    Sub OpenTxtFiles2()
    FPATH = "C:\Users\Andre\Desktop\excel\"
    Fname = Dir(FPATH & "*.txt")
    R = 2
    Do While Fname <> ""
      Open FPATH & Fname For Input As #1
      Do Until EOF(1)
            Line Input #1, textline
            Text = Text & textline
      Loop
      Close #1
      cellValue = Text
      openingParen = InStr(cellValue, "<TAG>")
      closingParen = InStr(cellValue, "</TAG>")
      enclosedValue = Mid(cellValue, openingParen + 5, closingParen - openingParen - 5)
      Cells(R, 2) = enclosedValue
      R = R + 1
      Fname = Dir
    Loop
    End Sub

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    I suspect the 2 in patel's
    Cells(R, 2) = enclosedValue
    should be a 1 if you want the results in column A
    Last edited by p45cal; 02-10-2014 at 11:16 AM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    you are right

  5. #5
    thanks a lot!!! patel and p45cal

Posting Permissions

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