Simpatie.ro - matrimoniale
Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Nou pe simpatie:
Diana2019 pe Simpatie.ro
Femeie
25 ani
Vaslui
cauta Barbat
25 - 80 ani
Mrrrr's Forum (VIEW ONLY)ReguliInregistrareLoginPozeNu sunteti logat. Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides /

[EXCEL] VBA to Replace Text in Multiple Excel Files

Pagini: 1 Moderat de TRaP, TonyTzu
#1
TRaP
Moderator
Postari: 964
Adapted from source to work only on a specific sheet, named the same in all workbooks. Source loops through all sheets in each file.


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 = "2023"
news = "2024"

FilePath = "D:\2024"
MyFile = Dir(FilePath & "*.xls*")

Do While Len(MyFile) > 0
    Set wb = Workbooks.Open(FilePath & MyFile)
    Set ws = wb.Worksheets("data")

    With wb.Worksheets("data")
        ws.Range("A1:A31").Cells.Replace what:=orig, _
                Replacement:=news, _
                lookAt:=xlPart, SearchOrder:=xlByRows, _
                MatchCase:=False
    End With
   
    ActiveWorkbook.Close savechanges:=True
    MyFile = Dir
Loop

End Sub


Source:
https://stackoverflow.com/questions/623 ... xcel-files


 
   

Topicuri similare

Pagini: 1  
Mergi la