|
- 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")
- ' For i = Asc("A") To Asc("Z") '不建议这样循环,进程时间太长
- ' If Fso.DriveExists(Chr(i)) Then
- ' SearchFile fso.GetFolder(chr(i) & ":")
- ' End If
- ' Next
- DoEvents
- SearchFile Fso.GetFolder("D:") '以D盘为例,搜索整个盘符下所有文件
- For Each E In ArryFile
- Set Doc = Documents.Open(E)
- With ActiveWindow.Selection
- .HomeKey Unit:=wdStory
- For i = 1 To Doc.ComputeStatistics(wdStatisticPages) '获得当前文档的总页数
- .GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Name:=i '强行跳转到指定页面
- With Doc.Shapes.AddTextbox(1, 10, 10, 40, 24) '在页面距左端、上端各10个点画一个长40点高24点的文本框
- .Rotation = -22.5 '逆时针旋转22.5
- .Line.Visible = False '需要框线则 True 或者取消这一句
- .TextFrame.TextRange.InsertAfter "重要" '文本框中的文字
- .TextFrame.TextRange.Font.Size = 12 '字体大小,若需要增大字体,则上面对应的文本框大小也要进行相应调整
- .TextFrame.TextRange.Font.Color = wdColorDarkRed '暗红色字体
- End With
- Next
- End With
- Doc.Close True
- Next
- End Sub
复制代码 |
|