把“雙壁單影”和“SD”儲存在文字檔案裡,中間用跳格鍵隔開,VBA增加以下程式碼: Dim Key As String, arrKey() As String, Key1 As String, Key2 As String If Dir(ActiveDocument.Path & "\keys.txt") = "" Then MsgBox "無法找到keys.txt!" Open ActiveDocument.Path & "\keys.txt" For Input As #1 Key = StrConv(InputB(LOF(1), #1), vbUnicode) Close #1 If Key = "" Or InStr(Key, vbTab) = 0 Then MsgBox "請先設定keys.txt裡的關鍵字!" arrKey = Split(Key, vbTab) Key1 = arrKey(0) Key2 = arrKey(1) If Key1 = "" Or Key2 = "" Then MsgBox "請先設定keys.txt裡的關鍵字!" With Application.FileSearch .FileName = "*.doc" .LookIn = MyValue .Execute MyFoundCount = .FoundFiles.Count For i = 1 To .FoundFiles.Count MyFoundFiles(i) = .FoundFiles(i) Next i End With For i = 1 To MyFoundCount Documents.Open FileName:=MyFoundFiles(i) With Selection.Find .Text = Key1 .Replacement.Text = Key2
把“雙壁單影”和“SD”儲存在文字檔案裡,中間用跳格鍵隔開,VBA增加以下程式碼: Dim Key As String, arrKey() As String, Key1 As String, Key2 As String If Dir(ActiveDocument.Path & "\keys.txt") = "" Then MsgBox "無法找到keys.txt!" Open ActiveDocument.Path & "\keys.txt" For Input As #1 Key = StrConv(InputB(LOF(1), #1), vbUnicode) Close #1 If Key = "" Or InStr(Key, vbTab) = 0 Then MsgBox "請先設定keys.txt裡的關鍵字!" arrKey = Split(Key, vbTab) Key1 = arrKey(0) Key2 = arrKey(1) If Key1 = "" Or Key2 = "" Then MsgBox "請先設定keys.txt裡的關鍵字!" With Application.FileSearch .FileName = "*.doc" .LookIn = MyValue .Execute MyFoundCount = .FoundFiles.Count For i = 1 To .FoundFiles.Count MyFoundFiles(i) = .FoundFiles(i) Next i End With For i = 1 To MyFoundCount Documents.Open FileName:=MyFoundFiles(i) With Selection.Find .Text = Key1 .Replacement.Text = Key2