Consulting

Results 1 to 3 of 3

Thread: Solved: Remove first character from text file

  1. #1

    Solved: Remove first character from text file

    I have some code written to remove the first character from my text file, but can seem to get it to work. I have a comma at the start of my text file when I extract the data from a word form, but it won't import correctly into my database without manually removing the comma. Can anyone help me modify my coding?

    Function myReplaceFileText(myFilePathInput As String, myFilePathOutput As String, myReplaceString As String, myString As String)
         
        Dim myFileString As String
         
        Open "C:\folder\file.txt" For Input As #1
        myFileString = Input(LOF(1), 1)
        Close #1
         
        myFileString = Replace(myFileString, myReplaceString, myString, Compare:=vbTextCompare)
        
        Open myFilePathOutput For Output As #2
        Print #2, myFileString
        Close
    End Function
    Sub Test()
         
        Dim myFilePathInput As String
        Dim myFilePathOutput As String
        Dim myReplaceString As String
        Dim myString As String
         
        myFilePathInput = "C:\folder\file.txt"
        myFilePathOutput = "C:\folder\file.txt"
        myReplaceString = ","
        myString = ""
         
        Call myReplaceFileText(myFilePathInput, myFilePathOutput, myReplaceString, myString)
         
    End Sub

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    992
    Location
    Welcome to the board!

    Nothing looks out of sorts.

    I changed the open line to
    [VBA] Open myFilePathInput For Input As #1[/VBA]
    and it worked as expected.

    David


  3. #3
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,273
    Location
    Cross-posted at: http://www.msofficeforums.com/word-v...text-file.html
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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