nguyenanhdung8111982
Thành viên hoạt động



- Tham gia
- 1/11/19
- Bài viết
- 120
- Được thích
- 33
- Giới tính
- Nam
Em có đoạn code như dưới dùng để repeleace hàng loạt file trong subfolder.
Khi em repleace cột V có kí tự: \\192.168.5.18 thành \\192.168.5.19 thì nó ra kết quả là \192.168.5.18
Khi em repleace \192.168.5.18 thành \\192.168.5.18 thì kết quả là 192.168.5.18
Nhưng khi em repleace 192.168.5.18 thành \\192.168.5.19 thì kết quả lại đúng. Em không biết bị đoạn nào.
Khi em repleace cột V có kí tự: \\192.168.5.18 thành \\192.168.5.19 thì nó ra kết quả là \192.168.5.18
Khi em repleace \192.168.5.18 thành \\192.168.5.18 thì kết quả là 192.168.5.18
Nhưng khi em repleace 192.168.5.18 thành \\192.168.5.19 thì kết quả lại đúng. Em không biết bị đoạn nào.
Mã:
Sub Change_directory_select()
Application.EnableEvents = False
Application.AskToUpdateLinks = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim fso As Object, fold As Object, fFile As Object
Dim fPath As String, fName As String, char_old As String, char_new As String
Dim wb As Workbook, ws As Worksheet
Dim lr As Long
fPath = InputBox("Enter path folder:")
Set fso = CreateObject("Scripting.FileSystemObject")
Set fold = fso.GetFolder(fPath)
char_old = Application.InputBox("Enter char finding:")
char_new = Application.InputBox("Enter replace char:")
For Each fFile In fold.SubFolders
fName = Dir(fFile.Path & "\*.xls", vbNormal)
i = 1
Do While fName <> ""
FileName = fso.GetBaseName(fFile.Path)
Set wb = Workbooks.Open(fFile.Path & "\" & fName)
Set ws = wb.Worksheets(1)
j = 2
While ws.Columns("V").Rows(j) <> ""
lr = wb.Sheets(1).Range("V" & Rows.Count).End(xlUp).Row
For j = 2 To lr
Range("V" & j) = Replace(Range("V" & j), char_old, char_new)
Next j
j = j + 1
Wend
nextcode:
wb.Close savechanges:=True
i = i + 1
fName = Dir
Loop
Next
MsgBox "Ho" & ChrW(224) & "n Th" & ChrW(224) & "nh !!!"
Application.EnableEvents = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.AskToUpdateLinks = True
End Sub