请教:如何在运用vba处理文件夹中所有的word文档?
Sub删除空白行()'删除空行,by不见不散,2006-1-15DimpAsParagraphDimrAsRangeDimsAsStringDimlAsLongForEa...
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 展开
'删除空行,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 展开
2个回答
展开全部
代码除了
For Each p InActiveDocument.Paragraphs
少了一个空格,而应该是
For Each p In ActiveDocument.Paragraphs
以外,应该没有问题。
楼主是不是想利用这段代码增加一些文档打开语句来处理文件夹中的所有Word文档呢?
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
附件请下载参考
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询