|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
给你一段代码,自己修改一下:
Sub test()
Dim myword, thispath, mydoc, s, s1, tm, r&
Set myword = CreateObject("word.application")
myword.Visible = True
thispath = ThisWorkbook.Path & "\"
mydoc = Dir(thispath & "*.doc")
Do While mydoc <> ""
r = r + 1
With myword
.documents.Open thispath & mydoc
.Selection.Find.MatchWildcards = True
s = "": s1 = ""
If .Selection.Find.Execute(s & "*" & s1) Then
tm = .Selection.Text
tm = Replace(Replace(Replace(tm, s, ""), " ", ""), Chr(13), "")
Cells(r + 2, 1) = tm: tm = ""
.Selection.MoveRight Unit:=1, Count:=1
End If
.documents.Close False
End With
mydoc = Dir
Loop
myword.Quit
End Sub |
|