偉婕您好:
我將該範例中的txt改為doc,但是出現錯誤訊息如下(如紅色所示)
Option Base 0
Sub Document_Open()
Dim arrStr() As String, InputStr As String
Fn = FreeFile
Open "c:\Replace.doc" For Input As #Fn '開啟Replace.doc檔
Application.ScreenUpdating = False '畫面暫停更新
While Not EOF(Fn)
Line Input #Fn, InputStr '從檔案讀出一列,
If Len(InputStr) > 0 And Mid(InputStr, 1, 1) <> "'" Then '若第一個字元是'就跳此列
arrStr = Split(InputStr, ",") '把讀入的文字列依逗號分成二個字串,置於 arrStr陣列內
Call ReplaceText(arrStr(0), arrStr(1)) '
End If
Wend
Application.ScreenUpdating = True '畫面恢復更新
Close #Fn
End Sub
Function ReplaceText(Src As String, Rpl As String) '這個函式會在整個檔案裡搜尋Src字串,將它取代為Rlp字串