Public Sub Rdoc()
If testing Then Exit Sub
On Error GoTo ErrorHandler
Dim currentRow As Integer
currentRow = ActiveCell.row
Dim dateStr As String
dateStr = format(Date, "yyyyMMdd")
Dim localPath As String
localPath = Cells(currentRow, 9)
Dim filePath As String
Dim wa As Variant
Dim wd As Word.document
If InStr(Cells(currentRow, 11), ".doc") > 0 Then
filePath = Cells(currentRow, 9) & Cells(currentRow, 11)
Set wa = CreateObject("Word.Application")
wa.Visible = False
Set wd = wa.Documents.Open(filePath)
Cells(currentRow, 10) = wd.Content.text
wd.Close savechanges:=False
wa.Quit
Set wa = Nothing
Else
Dim wildcard As String
wildcard = "*.doc*"
Dim fileText As String
Dim fso As Object
Dim objFolder As Object
Dim myFolder As Object
Dim myFile As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(localPath) Then
Set objFolder = fso.getfolder(localPath)
For Each myFolder In objFolder.SubFolders
For Each myFile In myFolder.files
If myFile.Name Like wildcard Or myFile.Name = wildcard Then
'MsgBox myFile.path
Set wa = CreateObject("Word.Application")
wa.Visible = False
Set wd = wa.Documents.Open(myFile.path)
fileText = fileText & wd.Content.text
wd.Close savechanges:=False
wa.Quit
Set wa = Nothing
End If
Next
Next
Set objFolder = Nothing
End If
Set fso = Nothing
Cells(currentRow, 10) = Cells(currentRow, 10) & fileText
End If
ErrorHandler:
If Err.Number <> 0 Then
MyMsgBox Err.Number & " " & Err.Description, 10
End If
End Sub
posted on 2018-12-27 10:21
萍水相逢 阅读(124)
评论(0) 编辑 收藏