|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub TEST()
Dim wdApp As Word.Application, wdDoc As Word.Document
Dim strFileName$, f, p$, strRngText$
p = ThisWorkbook.Path & "\"
With Application.FileDialog(4)
.InitialFileName = p
.AllowMultiSelect = True
If .Show Then p = .SelectedItems(1) & "\" Else Exit Sub
End With
Application.ScreenUpdating = False
Set wdApp = New Word.Application
For Each f In CreateObject("Scripting.FileSystemObject").GetFolder(p).Files
If f.Name Like "*.doc*" Then
strFileName = FName(f) & ".txt"
Set wdDoc = wdApp.Documents.Open(f.Path)
With wdDoc
strRngText = .Content.Text
Open strFileName For Output As #1
Print #1, strRngText
Close #1
End With
MsgBox wdDoc.Name
wdDoc.Close False
End If
Next
wdApp.Quit
Set wdApp = Nothing: Set wdDoc = Nothing
Application.ScreenUpdating = True
Beep
End Sub
Function FName(FileName As Variant) As String '取名称
Application.Volatile
FName = Left(FileName, InStrRev(FileName, ".") - 1)
End Function |
|