今日收到網(wǎng)友求助,實(shí)現(xiàn)多工作簿下面多個(gè)關(guān)鍵字替換,,一看就沒看過我的前面的文章案例,,之前寫過一個(gè),今日再次寫下,,其實(shí)原理很簡單,,分析下需求: 【1】問題描述: 希望對(duì)大量工作簿的全部sheet的多個(gè)關(guān)鍵字進(jìn)行替換: 圖1 對(duì)里面的紅色文字按照對(duì)應(yīng)關(guān)系進(jìn)行替換: 圖2 【2】分析思路 1:利用VBA循環(huán)打開工作簿,循環(huán)多個(gè)sheet,,利用replace來進(jìn)行替換 2:將圖2的內(nèi)容放入數(shù)組,實(shí)現(xiàn)多關(guān)鍵字替換 3:單個(gè)工作簿循環(huán)完畢后保存,,關(guān)閉,,再進(jìn)行下一個(gè)。 【3】結(jié)果驗(yàn)證 代碼 Sub QQ372936709() Application.DisplayAlerts = False Application.ScreenUpdating = False Application.AskToUpdateLinks = False arr = ActiveSheet.Range('a2').CurrentRegion Dim wb As Workbook myname = Dir(ThisWorkbook.Path & '\' & '*.xls*') Do While myname <> '' If myname <> ThisWorkbook.Name Then Set wb = Workbooks.Open(ThisWorkbook.Path & '\' & myname) For i = 1 To wb.Sheets.Count For j = 1 To UBound(arr) wb.Sheets(i).UsedRange.Replace arr(j, 1), arr(j, 2) Next Next Application.Windows(wb.Name).Visible = True wb.Close 1 Else End If myname = Dir Loop Application.DisplayAlerts = True Application.ScreenUpdating = True Application.AskToUpdateLinks = True MsgBox '完成替換' End Sub |
|