vba 检索一个文件夹里的word文件并修改其内容
本人想用vba代码检索一个文件夹里的word文件(.doc文件)并逐个提起word中的内容,请高手指点,本人是刚刚接触的.....
[解决办法]
'具体代码还要你自己写啊,给个方法吧
'添加一个filelistbox,名字file1,设置好属性,来获取某路径下的全部doc文件
file1.visible=false
file1.path=你的文件夹路径
file1.pattern="*.doc"
for i=0 to file1.listcount-1
Set objword = New Word.Application '生成word实例
objword.Visible = False '显示word窗口
objword.Documents.Open (你的文件夹路径 & "" & file1.list(i)) '打开一个文档
'你的处理代码
'......
objword.Quit '退出word
Set objword = Nothing '释放资源
next i
Dim wordd
Private Sub Command1_Click()
Set wordd = CreateObject("Word.Application")
wordd.Documents.open "c:\muoban.doc"
wordd.Visible = True
wordd.Activate
'查找内容并替换内容
With wordd.Selection.Find
.Text = "查找内容"
.Replacement.Text = "替换内容"
.Forward = True
.Wrap = 1
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wordd.Selection.Find.Execute Replace:=2
wordd.ActiveDocument.Save
wordd.Application.Quit
End Sub