.Find Loop Word 2013
.Find Loop Word 2013
我有一个包含纯文本的文档,我想在将其移动到 Access 之前进行一些预格式化。目前,我在 Word 中尝试将格式分离为标题和文本。该文档有数百个标题,每个标题后都有小的解释文本(这是一本针对一台机器进行解释的错误手册)。
我正在尝试将唯一字符串放在以 "start-of-title" 唯一字符串开头的通道的末尾。
我想创建一个宏来找到那个字符串,然后走到通道的尽头并写入“end-of-title”,直到找到结果为止。
我到目前为止所做的,并且一次有效,如下:
Sub test3()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "startoftitle "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" endoftitle"
End Sub
我尝试过循环,但遗憾的是我无法使用正确的语法。问题是在没有找到结果之前我不能让它循环...
应该这样做
Sub test3()
Const STARTTOKEN = "startoftitle "
Const ENDTOKEN = " endoftitle"
For i = 1 To ThisDocument.Paragraphs.Count
If ThisDocument.Paragraphs(i).Range.Style = "Title" _
And Left(ThisDocument.Paragraphs(i).Range.Text, Len(STARTTOKEN)) <> STARTTOKEN Then
ThisDocument.Paragraphs(i).Range.Text = STARTTOKEN & ThisDocument.Paragraphs(i).Range.Text & ENDTOKEN
End If
Next i
End Sub
我在检查你写的内容之前设法解决了它。感谢您的帮助!
这里是任何有同样问题的人的代码:
Sub test3()
'
' test3 Macro
'
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = " startoftitle "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While Selection.Find.Execute = True
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" endoftitle"
Loop
End Sub
我有一个包含纯文本的文档,我想在将其移动到 Access 之前进行一些预格式化。目前,我在 Word 中尝试将格式分离为标题和文本。该文档有数百个标题,每个标题后都有小的解释文本(这是一本针对一台机器进行解释的错误手册)。
我正在尝试将唯一字符串放在以 "start-of-title" 唯一字符串开头的通道的末尾。
我想创建一个宏来找到那个字符串,然后走到通道的尽头并写入“end-of-title”,直到找到结果为止。
我到目前为止所做的,并且一次有效,如下:
Sub test3()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "startoftitle "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" endoftitle"
End Sub
我尝试过循环,但遗憾的是我无法使用正确的语法。问题是在没有找到结果之前我不能让它循环...
应该这样做
Sub test3()
Const STARTTOKEN = "startoftitle "
Const ENDTOKEN = " endoftitle"
For i = 1 To ThisDocument.Paragraphs.Count
If ThisDocument.Paragraphs(i).Range.Style = "Title" _
And Left(ThisDocument.Paragraphs(i).Range.Text, Len(STARTTOKEN)) <> STARTTOKEN Then
ThisDocument.Paragraphs(i).Range.Text = STARTTOKEN & ThisDocument.Paragraphs(i).Range.Text & ENDTOKEN
End If
Next i
End Sub
我在检查你写的内容之前设法解决了它。感谢您的帮助!
这里是任何有同样问题的人的代码:
Sub test3()
'
' test3 Macro
'
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = " startoftitle "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While Selection.Find.Execute = True
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" endoftitle"
Loop
End Sub