Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

VBA Read Txt Files In A Folder And Delete First Line According To A Criteria

I have put this question before and this is the code which has been kindly sent by the expert "@aikimark".

---------------------------------------------------------------------------------------------------------------------------
Public Sub Q_28550315()
    Dim strFile As String
    Const cPath As String = "C:\users\aikimark\downloads\"
    Const cDefault As String = "10      Session      2010      2010"
    Dim strLine As String
    Dim colLines As Collection
    Dim vItem As Variant
    Dim intFN As Integer
    strFile = Dir(cPath & "*.txt")
    Do Until Len(strFile) = 0
        Set colLines = Nothing
        Set colLines = New Collection
        intFN = FreeFile
        Open cPath & strFile For Input As #intFN
        Do Until EOF(intFN)
            Input #intFN, strLine
            If Right(strLine, 4) = ".exl" Then
            Else
                colLines.Add strLine
            End If
        Loop
        Close intFN
        Open cPath & strFile For Output As #intFN
        If colLInes.Count = 0 Then
            Print #intFN, cDefault
        Else
            For Each vItem In colLines
                Print #intFN, vItem
            Next
        End If
        Close intFN
        strFile = Dir
    Loop
End Sub
----------------------------------------------------------------------------------------------------------------------------------------------

After this question has been accepted (closed) I have spotted a problem which is:
- if the "txt" file contains "," then the "sub" above will generate a file which creates a new line after each of those ",".
Would it be possible to "ignore" the "," and keep the line as it is?

Thanks.
0
Duke001
Asked:
Duke001
  • 4
  • 3
1 Solution
 
Phillip BurtonCommented:
Change the line starting

Input

to

Line Input
0
 
Duke001Author Commented:
Amazing stuff! It works perfectly.

I would like to ask you if you could help to understand why the following code doest work?
Please let me know if I need to open another question?

Thanks
0
 
Phillip BurtonCommented:
Another question is always nice, because it might not be in my expertise, and would advertise to other experts more.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Duke001Author Commented:
hoops! forgot to paste the code

Line 1: Sub test()
Line 2: Dim WshShell As Object
Line 3: Set WshShell = CreateObject("WScript.Shell")
Line 4: WshShell.Run "cmd /K cscript C:\Test1\Make_L_JP.vbs"
Line 5: End Sub
0
 
Duke001Author Commented:
Quick and efficient!
0
 
Phillip BurtonCommented:
Sorry - WScript not in my expertise.
0
 
Duke001Author Commented:
I understand.
Thanks any away
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now