Nguyen Anh Dung
Board Regular
- Joined
- Feb 28, 2020
- Messages
- 180
- Office Version
- 2016
- Platform
- Windows
i have code as below use repeleace all file in subfolder.
when repleace column V : \\192.168.5.18 to \\192.168.5.19 is result \192.168.5.18
when repleace \192.168.5.18 to \\192.168.5.18 s result 192.168.5.18
But repleace 192.168.5.18 to \\192.168.5.19 is correct.
Best regards!!!
Nguyen Anh Dung
when repleace column V : \\192.168.5.18 to \\192.168.5.19 is result \192.168.5.18
when repleace \192.168.5.18 to \\192.168.5.18 s result 192.168.5.18
But repleace 192.168.5.18 to \\192.168.5.19 is correct.
Code:
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
Nguyen Anh Dung