|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 413191246se 于 2016-5-19 16:29 编辑
139:查找和替换的VBA我搞不好,重新修改了一下,这回似乎没问题了!你试试吧!
- Sub 查找红色文字提取到空白文档()
- Dim i As String, doc As Document, j As Long
- i = ActiveDocument.Name
- recome:
- Selection.HomeKey Unit:=wdStory
- Do
- With Selection.Find
- .ClearFormatting
- .Font.Color = wdColorRed
- .Execute
- If Selection.Find.Found = True Then
- If j = 1 Then GoTo conti
- '
- Selection.EndKey Unit:=wdStory
- Selection.TypeParagraph
- Selection.TypeText Text:="速413191246se结"
- Selection.Paragraphs(1).Range.Select
- Selection.Font.Color = wdColorRed
- '
- Set doc = Documents.Add
- Documents(i).Activate
- j = 1
- GoTo recome
- conti:
- If Selection.Text = "速413191246se结" & vbCr Then
- ActiveDocument.Close savechanges:=wdDoNotSaveChanges
- doc.Paragraphs.Last.Range.Delete
- MsgBox "提取完毕!文档尚未保存!", vbOKOnly + vbExclamation, "查找和替换": End
- End If
- Selection.Copy
- Documents(doc).Activate
- Selection.Paste
- doc.Characters(1).Copy
- Selection.TypeParagraph
- Documents(i).Activate
- Else
- ActiveDocument.Close savechanges:=wdDoNotSaveChanges
- MsgBox "未找到红色文字!", vbOKOnly + vbCritical, "查找和替换": End
- End If
- End With
- Loop Until Selection.Find.Found = False
- End Sub
复制代码 |
|