|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 duquancai 于 2016-7-10 11:01 编辑
用遍历所有文件夹中的文件,但是你没有提供主文件夹路径,不会是遍历整个磁盘吧?呵呵!还有具体怎么修改页眉页脚?最好上传附件以便测试。请测试以下代码:
Sub 遍历所有文件夹中的文件()
Dim arr(1 To 100000) As String, i&, k&, x&, f$, f1$, oDoc As Document
Dim Osec As Section, Ohefo As HeaderFooter
Application.ScreenUpdating = False
arr(1) = "D:\这里输入文件夹路径\" '这里输入文件夹路径
i = 1: k = 1
Do While i < UBound(arr)
If arr(i) = "" Then Exit Do
f = Dir(arr(i), vbDirectory)
Do
If InStr(f, ".") = 0 And f <> "" Then
k = k + 1
arr(k) = arr(i) & f & "\"
End If
f = Dir
Loop Until f = ""
i = i + 1
Loop
For x = 1 To UBound(arr)
If arr(x) = "" Then Exit For
f1 = Dir(arr(x) & "*.doc*")
Do While f1 <> ""
Set oDoc = Documents.Open(arr(x) & f1, Visible:=False)
For Each Osec In oDoc.Sections
For Each Ohefo In Osec.Headers
Ohefo.Range.InsertAfter "添加页眉文字" '这里输入需要添加的字符
Next
Next
oDoc.Close True
Set oDoc = Nothing
f1 = Dir
Loop
Next x
Application.ScreenUpdating = True
End Sub
|
|