我只是在學習,還不太了解。我寫了錯誤的代碼
Sub sierotkiTXT_select()
Do
Selection.EndKey Unit:=wdLine
Selection.MoveLeft Unit:=wdCharacter, Count:=3, Extend:=wdExtend
If Selection.Text Like "* [aAwWzZiIoOuUVQ] *" Or Selection.Text Like "*[A-Z]. *" Or Selection.Text Like "* [a-z]. *" Or Selection.Text Like "*z. *" Or Selection.Text Like "*:] *" Then
Result = MsgBox("OK?", vbYesNoCancel vbQuestion)
If Result = vbYes Then
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete
Selection.InsertAfter Text:=ChrW(160)
End If
If Result = vbCancel Then
Exit Sub
End If
End If
Selection.MoveRight Unit:=wdCharacter, Count:=3
Loop Until Selection.Text = ActiveDocument.Range.Characters.Last
End Sub
并且不知道如何在檔案末尾停止這樣的宏(打破回圈)而不使用
Loop Until Selection.Text = ActiveDocument.Range.Characters.Last
這不是問題,但宏有時會停在段落結尾字符處,將它們解釋為檔案的結尾。[編輯] Ok-ActiveDocument.Range.Characters.Last 仍然回傳空 - 這就是它停止的原因。我不應該使用這個。
示例(正文): 之前
運行宏后: 后
示例(尾注): 之前 之后
uj5u.com熱心網友回復:
你甚至不需要宏!您只需要兩個通配符查找/替換操作,其中一個具有:
Find = (<[A-Za-z])^32
Replace = \1^s
和一個:
Find = (<[a-z].)^32
Replace = \1^s
另請參閱:https ://www.msofficeforums.com/word-vba/48717-how-i-find-character-line.html
uj5u.com熱心網友回復:
我更正了我的代碼并且它有效。
Sub sierotkiTXT_select()
'szukaj sierotek
Dim NumLines As Long
Application.ScreenUpdating = True
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
NumLines = Selection.Range.ComputeStatistics(wdStatisticLines)
MsgBox "Lines to check " & (NumLines)
Selection.Collapse
For i = 1 To NumLines
Selection.EndKey Unit:=wdLine
Selection.MoveLeft Unit:=wdCharacter, Count:=3, Extend:=wdExtend
If Selection.Text Like "* [aAwWzZiIoOuUVQ] *" Or Selection.Text Like "*[A-Z]. *" Or Selection.Text Like "* [a-z]. *" Or Selection.Text Like "*z. *" Or Selection.Text Like "*:] *" Then
Result = MsgBox("Akceptujesz?", vbYesNoCancel vbQuestion)
If Result = vbYes Then
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete
Selection.InsertAfter Text:=ChrW(160)
End If
If Result = vbCancel Then
Exit Sub
End If
End If
Selection.MoveRight Unit:=wdCharacter, Count:=3
Next
End Sub
uj5u.com熱心網友回復:
就我而言,我發現我可以使用 Search/Replace 函式而不是宏 BUT 而不是在 a、i、o、u、w、z 之后插入每個硬空格(在我的情況下,這會使對齊的文本看起來很糟糕并且不必要地移動所有文本),我可以使用
搜索:
空間([aAwWzZiIoOuU])空間
替換為:space\1ZERO WIDTH JOINERspace
其中 ZERO WIDTH JOINER 是 Unicode 字符 U 200D。如何在 Microsoft Windows 中鍵入:Alt (在 NumPad 鍵盤上)08205
ZERO WIDTH JOINER 在 WORD 中看起來像這樣(啟用“顯示隱藏字符”選項): ZERO WIDTH JOINER image
下面是使用硬空格和使用零寬度連接符 空格鍵后文本在我的案例中的外觀示例: 示例
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/525178.html
