我正在尝试在单独的EXCEL单元格中导出Word文档句子。 Basicaly我想通过一个特定的分隔符(任意)分离WORD文档的不同部分,并将分离的句子导入EXCEL的单独单元格中。
Sub TheBoldAndTheExcelful()
Dim docCur As Document
Dim snt As Word.Range
Dim i As Integer
Dim j As Integer
Set snt = ActiveDocument.Range
'Requires a reference to the 'Microsoft Excel XX.0 Object Library'
Dim appXL As Excel.Application, xlWB As Excel.Workbook, xlWS As Excel.Worksheet
'This assumes excel is currently closed
Set appXL = CreateObject("Excel.Application")
appXL.Visible = True
Set xlWB = appXL.Workbooks.Add
Set xlWS = xlWB.Worksheets(1)
j = 1
On Error GoTo ErrHandler
Application.ScreenUpdating = False
Set docCur = ActiveDocument.Range
For Each snt In docCur.Sentences
With snt.Find
.Text = "Technical Indicators and Signals"
While .Execute
j = j + 1
xlWS.Cells(j, i).Value = snt.Text
Wend
End With
Next snt
ExitHandler:
Application.ScreenUpdating = True
Set snt = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Sub
执行上述代码时遇到类型不匹配错误
。