请教:如何在运用vba处理文件夹中所有的word文档?

Sub 删除空白行()
'删除空行,by不见不散,2006-1-15
Dim p As Paragraph
Dim r As Range
Dim s As String
Dim l As Long
For Each p InActiveDocument.Paragraphs
Set r = p.Range
s = CStr(r.Text)
l = Asc(s)
If (l = 13 Or l =11) Then r.Text = ""
Next p
End Sub

代码除了
For Each p InActiveDocument.Paragraphs
少了一个空格,而应该是
For Each p In ActiveDocument.Paragraphs
以外,应该没有问题。
楼主是不是想利用这段代码增加一些文档打开语句来处理文件夹中的所有Word文档呢?追问

完全正确!就是您的这个意思。

追答Option Explicit

Sub DelBlankVol()

Dim Self$, CurrPath$, CurrFile$, l!

Dim Doc As Document, p As Paragraph

CurrPath = ThisDocument.Path & "\"

Self = ThisDocument.Name

CurrFile = Dir(CurrPath)

Do Until CurrFile = ""

    If CurrFile <> Self And CurrFile <> "." And CurrFile <> ".." And (LCase(Right(CurrFile, 5)) = ".docx" Or LCase(Right(CurrFile, 4)) = ".doc") Then

        Set Doc = Documents.Open(CurrPath & CurrFile)

        For Each p In Doc.Paragraphs

            

            l = Asc(CStr(p.Range.Text))

            On Error Resume Next

            If (l = 13 Or l = 11) Then p.Range.Text = ""

            On Error GoTo 0

        Next p

        Doc.Save

        Doc.Close

        Set Doc = Nothing

    End If

    CurrFile = Dir()

Loop

End Sub

附件请下载参考

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-07-21
要处理什么?追问

Sub 删除空白行()

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网