|
- Sub Word2007循环遍历文件夹()
- '注意:仅处理文件夹(不包含子文件夹)
- Dim i$, p$, n&
- p = "E:\abc" '此路径自己改(两个斜杠不要删除!)
- i = Dir(p & "*.docx")
- Do While i <> ""
- Documents.Open FileName:=p & i '打开文档
- 删除关键词所在行至文档末尾内容 '单个文档处理(将处理单个文档的宏名粘贴到这里)
- ActiveDocument.Close savechanges:=wdSaveChanges '关闭并保存文档
- n = n + 1
- i = Dir
- Loop
- MsgBox "共处理 " & n & " 个文档!", 0 + 48
- End Sub
- Sub 删除关键词所在行至文档末尾内容()
- Dim a, i&, doc As Document
- Set doc = ActiveDocument
- a = Array("还看了", "猜你喜欢", "相关文章", "你感兴趣的")
- With doc.Content.Find
- .ClearFormatting
- For i = 0 To 3 '搜索 4 个词,这里就写 3;如果搜索 8 个词,就写 7
- .Text = a(i)
- .Execute
- If .Found = True Then
- .Parent.Font.Color = wdColorRed '红色(此行语句可以删除)
- doc.Range(Start:=.Parent.Paragraphs(1).Range.Start, End:=doc.Content.End).Delete
- .Parent.Start = doc.Content.Start
- End If
- Next i
- End With
- End Sub
复制代码 |
|