|
* 第 4 行代码:当 s=1 时,英式 转 美式 / 当 s=2 时,美式 转 英式(可自行修改,仅限 1/2 两个值)
* 为自己方便(因为我用的是 Win10-64位系统,汉字直接拷贝到帖子会变成乱码,所以全用英文字符)
- Sub aaaa_UK2US()
- If Documents.Count = 0 Then MsgBox "Please open the text file - variants.txt!", 0 + 16: End
- If ActiveDocument.Name <> "variants.txt" Then MsgBox "Please open the text file - variants.txt!", 0 + 16: End
-
- Const s As Long = 1 '(1=UK2US/2=US2UK)
- Dim arr, brr, i&, y$
-
- 'arr
- ActiveDocument.Content.Find.Execute "^9*(^13)", , , 1, , , , , , "\1", 2
- ActiveDocument.Paragraphs.Last.Range.Delete
- arr = Split(ActiveDocument.Content.Text, vbCr)
-
- 'brr
- y = ActiveDocument.FullName
- ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
- Documents.Open FileName:=y
- ActiveDocument.Content.Find.Execute "<*^9(*^13)", , , 1, , , , , , "\1", 2
- ActiveDocument.Paragraphs.Last.Range.Delete
- brr = Split(ActiveDocument.Content.Text, vbCr)
- ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
-
- 'replace
- Dim pPath$, f As Object, fd As Object, fso As Object, Stack$(), top&, n&, stxt$, doc As Document, x&
- pPath = MySelectFolder
- Set fso = CreateObject("Scripting.FileSystemObject")
- top = 1
- ReDim Stack(0 To top)
- Do While top >= 1
- For Each f In fso.getfolder(pPath).Files
- n = n + 1
- stxt = f.Path
- If stxt Like "*.doc*" Then
- Set doc = Documents.Open(FileName:=stxt)
- '-----------------------------------------------------------
- For i = 0 To UBound(arr) - 1
- With Selection
- .HomeKey 6
- With .Find
- .ClearFormatting
- If s = 1 Then
- .Text = arr(i)
- .Replacement.Text = brr(i)
- Else
- .Text = brr(i)
- .Replacement.Text = arr(i)
- End If
- .Forward = True
- .MatchWildcards = False
- .MatchWholeWord = True
- Do While .Execute
- With .Parent
- With .Font
- .Color = wdColorRed
- .Underline = wdUnderlineSingle
- End With
- .Start = .End
- End With
- Loop
- End With
- End With
- Next
- '------------------------------------------------------------
- doc.Close SaveChanges:=wdSaveChanges
- x = x + 1
- End If
- Next
- For Each fd In fso.getfolder(pPath).SubFolders
- Stack(top) = fd.Path
- top = top + 1
- If top > UBound(Stack) Then ReDim Preserve Stack(0 To top)
- Next
- If top > 0 Then pPath = Stack(top - 1): top = top - 1
- Loop
- Set f = Nothing
- Set fd = Nothing
- Set fso = Nothing
- MsgBox "Total files = " & n & vbCr & "Word Files(*.docx/*.doc) = " & x, 0 + 48
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|