原因在于替换中有“\(\\)”的存在,WORD无法区分在使用通配符时的该标记。分两步替换。
Sub replepath() Dim OldText As String, NewText As String Application.ScreenUpdating = False With ActiveDocument .ActiveWindow.View.ShowFieldCodes = True NewText = .path NewText = VBA.Replace(NewText, "\", "//") OldText = "LINK Excel.Sheet.8 ""*(所得税汇算清缴工作底稿.xls"")" With .Content.Find .ClearFormatting .Text = OldText .MatchWildcards = True .Replacement.Text = "LINK Excel.Sheet.8 """ & NewText & "//" & "\1" .Execute Replace:=wdReplaceAll .ClearFormatting .Text = "//" .MatchWildcards = False .Replacement.Text = "\\" .Execute Replace:=wdReplaceAll End With .ActiveWindow.View.ShowFieldCodes = False .Fields.Update End With Application.ScreenUpdating = True End Sub |