Chào ace
Em có tìm đc 1 đoạn code chia sẻ trên microsoft và e đang cần sử dụng nó.
Mục đích: tìm và thay thế 1 đoạn văn bản trong nhiều file excel trong 1 thư mục cùng lúc.
hiện tại e đang gặp lỗi
1. sau khi load file excel nhưng ko replace được, ko hiện thông báo done
2. không gõ tiếng việt vào ô tìm kiếm và thay thế đc.
(e đã enable editing all file)
Nhờ ace chỉ giúp ạ
Link gốc: https://answers.microsoft.com/en-us...a/deb409ac-8467-4648-a44d-f1dd47b7d45d?auth=1
Em có tìm đc 1 đoạn code chia sẻ trên microsoft và e đang cần sử dụng nó.
Mục đích: tìm và thay thế 1 đoạn văn bản trong nhiều file excel trong 1 thư mục cùng lúc.
hiện tại e đang gặp lỗi
1. sau khi load file excel nhưng ko replace được, ko hiện thông báo done
2. không gõ tiếng việt vào ô tìm kiếm và thay thế đc.
(e đã enable editing all file)
Nhờ ace chỉ giúp ạ
Link gốc: https://answers.microsoft.com/en-us...a/deb409ac-8467-4648-a44d-f1dd47b7d45d?auth=1
Mã:
Sub ReplaceInFolder()
Dim strPath As String
Dim strFile As String
Dim wbk As Workbook
Dim wsh As Worksheet
Dim strFind As String
Dim strReplace As String
strFind = InputBox("Enter text to find")
If strFind = "" Then
MsgBox "No find text specified!", vbExclamation
Exit Sub
End If
strReplace = InputBox("Enter replacement text")
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then
strPath = .SelectedItems(1)
Else
MsgBox "No folder selected!", vbExclamation
Exit Sub
End If
End With
If Right(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
Application.ScreenUpdating = False
strFile = Dir(strPath & "*.xls*")
Do While strFile <> ""
Set wbk = Workbooks.Open(Filename:=strPath & strFile, AddToMRU:=False)
For Each wsh In wbk.Worksheets
wsh.Cells.Replace What:=strFind, Replacement:=strReplace, _
LookAt:=xlWhole, MatchCase:=False
Next wsh
wbk.Close SaveChanges:=True
strFile = Dir
Loop
Application.ScreenUpdating = True
End Sub
Lần chỉnh sửa cuối: