|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
下边这段代码经测试可用,自动遍历修改页眉;求大侠帮助做个修改。我现在不需要修改页眉,需要自动执行另一个宏,宏1
就是把修改页眉换为自动执行另一个宏
=====================
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
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = False Then Exit Sub
arr(1) = .SelectedItems(1) & "\"
End With
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
|
|