|
楼主 |
发表于 2015-11-5 23:01
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
最近找到2个vba代码,第一个是查找所有word文件里的关键字的,第二个是加编号的,但是加编号的只能在一个word文件使用,求编程高人把这个两个编程合并一下,搜索(2015)第*号,所有word文件标题后面的(2015)第 号都能依次填入编号
这是第一个
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim myPas As String, myPath As String, i As Integer, myDoc As Document
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "选择目标文件夹"
If .Show = -1 Then
myPath = .SelectedItems(1)
Else
Exit Sub
End If
End With
myPas = InputBox("请输入打开密码:")
With Application.FileSearch
.LookIn = myPath
.FileType = msoFileTypeWordDocuments
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Set myDoc = Documents.Open(FileName:=.FoundFiles(i), Passworddocument:=myPas)
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "中微子工作室"
.Replacement.Text = "www.jihetu.com"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
myDoc.Save
myDoc.Close
Set myDoc = Nothing
Next
End If
End With
Application.ScreenUpdating = True
End Sub
这是第二个
Sub rank()
Rem 按顺序插入数字
Selection.Find.Text = "[]"
Selection.Find.Forward = True
For i = 1 To 10
Selection.Find.Execute
RS = "[" + Format(i, "##") + "]"
Selection.Find.Replacement.Text = RS
Selection.Collapse Direction:=wdCollapseStart
Selection.Find.Execute Replace:=wdReplaceOne
Next i
End Sub |
|