|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
以下代码,建议放在标准模块中运行
- Dim ArryFile(), nFile '全局变量
- Function SearchFile(ByVal Fd)
- On Error Resume Next
- Dim Fl
- Dim SubFd
- Dim i As Integer
- i = Fd.Files.Count
- If i > 0 Then
- '--------------------------------------------------
- Set RegX = CreateObject("VBSCRIPT.REGEXP") 'RegEx为建立正则表达式
- With RegX
- .Global = True '设置全局可用
- .Pattern = "(doc|docx|doxm)$" '输入后缀名用|隔开"(xls|xlsx|docx|doc)$ ,只返回括号中对应文件类型的文件列表
- End With
- '--------------------------------------------------
- ReDim Preserve ArryFile(1 To nFile + i)
- For Each Fl In Fd.Files
- If RegX.test(Fl.Name) = True Then
- nFile = nFile + 1
- ArryFile(nFile) = Fl.Path
- End If
- Next
- End If
- If Fd.SubFolders.Count = 0 Then Exit Function
- For Each SubFd In Fd.SubFolders '遍历子目录
- SearchFile SubFd
- Next
- End Function
- Sub 批量删除当前目录下WORD文档最后一页空白行()
- Dim Doc As Document
- Dim Fso
- Set Fso = CreateObject("Scripting.FileSystemObject")
- nFile = 0
- Set Fso = CreateObject("Scripting.FileSystemObject")
- DoEvents
- SearchFile Fso.GetFolder(ThisDocument.Path & "")
- For Each E In ArryFile
- Set Doc = Documents.Open(E)
- With ActiveWindow.Selection
- .GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Name:=Doc.ComputeStatistics(wdStatisticPages) '强行跳转到最后一页
- .EndKey Unit:=wdStory, Extend:=wdExtend
- If .Paragraphs.Count = 1 Then '针对只有一行的情况
- .Font.Size = 1
- With Selection.ParagraphFormat
- .LeftIndent = CentimetersToPoints(0)
- .RightIndent = CentimetersToPoints(0)
- .LineSpacingRule = wdLineSpaceExactly
- .LineSpacing = 1
- End With
- End If
- End With
- Doc.Close True
- Next
- End Sub
复制代码 |
|