PDA

View Full Version : [SOLVED] First to digit remove from text file without open by vba coding



manish1982
10-18-2013, 12:18 AM
"i have a text file i have 12 digits string i want to delet first 2 digits withou open the text file , i am also attached a script with this i have coding pleaseTxt file is below like , i want this change without opme text file because files is very huge.""919712121210""919712121211""919712121212""919712121214""I need like this"" 9712121210,Massage""9712121211,Massage""9712121212,Massage""9712121214,Massage""Below is the coding "

Sub Test()
Dim fn As String, txt As String, myWord As String, Counter As Integer,
Filename1 As String Counter = 4
If Cells(Counter, 1).Value "" Then
Set currentWB = ActiveWorkbook
Do While fn = Cells(Counter, 1).Value ""
fn = Cells(Counter, 1).Value
myWord = Cells(Counter, 12).Value
Filename1 = Cells(Counter, 9).Value
On Error Resume Next
OR
On Error GoTo 0
On Error GoTo ErrO
txt = CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll
Open fn For Output As #1 Print #1, Replace(txt, vbCrLf, myWord & vbCrLf), Close #1
Counter = Counter + 1
'On Error GoTo ErrH
Loop
Else
MsgBox "Mass row files are not attached", vbExclamation
Exit Sub
End If
ErrO: Select Case Err
Case 68, 75, 62: ' Error 68: "Device not available" ' Error 75: "Path/File Access Error"
MsgBox "There is an error reading drive B."
Case 76, 55: ' Error 76: "Path not found"
MsgBox "The specified path is not found."
Case 5: ' Error 5: "Files format not correct"
MsgBox "Files are not correct."
Case Else: ' An error other than 68, 75 or 76 has occurred.
' Display the error number and the error text.
MsgBox "Error # " & Err & " : " & Error(Err)
End Select
End Sub

SamT
10-19-2013, 07:47 AM
Not enough information.

Please copy 10 lines from the txt file into Notepad and save the Notepad file as Example.txt and attach it to your next post.

Also, copy the worksheet with the file names to a new workbook, delete all except the top ten rows, (first three rows and 7 data rows,) and attach the new workbook.

You can attach files by using the "Go Advanced" button below the post editor, then using the "Manage Attachments" button below the Advanced post editor.

manish1982
10-20-2013, 09:00 PM
i have resolved self , i hope i will tuch with you next time thanks for support VBA Team.