HỖ TRỢ
02516-544-809
1900-636-507
 
Giờ làm việc
Sáng 07h30 đến 12h00
Chiều 13h30 đến 17h00
EL0008 | Relace text many file at one by VBA (including textBox affected)

Sub ReplaceStringInExcelFiles()

    Dim MyFile As String
    Dim FilePath As String
    Dim orig As String
    Dim news As String
    Dim wb As Workbook, ws As Worksheet

    orig = "dog"
    news = "cow"

    FilePath = "F:\DESTOP00\1\"
    MyFile = Dir(FilePath & "*.xls*")


    Do While Len(MyFile) > 0
        Set wb = Workbooks.Open(FilePath & MyFile) '<< assign the workbook to wb
        'Loop over the worksheets
        'Note: no need to activate/select
        For Each ws In wb.Worksheets
            ws.UsedRange.Cells.Replace what:=orig, _
                            Replacement:=news, _
                            lookAt:=xlPart, SearchOrder:=xlByRows, _
                            MatchCase:=False


     'xu ly cho textbox                       
    On Error Resume Next
    For Each shp In ws.Shapes
    xValue = shp.TextFrame.Characters.Text
    shp.TextFrame.Characters.Text = VBA.Replace(xValue, orig, news, 1)
    Next
                            
                            
        Next ws
        ActiveWorkbook.Close savechanges:=True
        MyFile = Dir
    Loop

End Sub

0
Giỏ hàng
Chat ngay
Hotline02516544809
Chat ngay