Solved

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

Posted on 2014-11-13
7
292 Views
Last Modified: 2014-11-13
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
Comment
Question by:Duke001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40439908
Change the line starting

Input

to

Line Input
0
 

Author Comment

by:Duke001
ID: 40439958
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
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40439969
Another question is always nice, because it might not be in my expertise, and would advertise to other experts more.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Duke001
ID: 40439991
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
 

Author Closing Comment

by:Duke001
ID: 40440001
Quick and efficient!
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40440008
Sorry - WScript not in my expertise.
0
 

Author Comment

by:Duke001
ID: 40440153
I understand.
Thanks any away
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question