根据Word中的长下划线/下划线分隔文本,然后使用VBA将表格传输到Excel
我有一个表格在word中,我想把它带到excel中,我使用下面的代码从达蒙实现同样使用VBA。在执行此操作时,我需要帮助将给定word表中由长下划线/长下划线分隔的文本转移到excel中的列根据Word中的长下划线/下划线分隔文本,然后使用VBA将表格传输到Excel,excel,vba,ms-word,export-to-excel,text-processing,Excel,Vba,Ms Word,Export To Excel,Text Processing,我有一个表格在word中,我想把它带到excel中,我使用下面的代码从达蒙实现同样使用VBA。在执行此操作时,我需要帮助将给定word表中由长下划线/长下划线分隔的文本转移到excel中的列 Sub ImportWordTables() 'Imports cells (2,2) from Word document Tables 1-10 Dim wdDoc As Word.Document Dim wdFileName As Variant Dim
Sub ImportWordTables()
'Imports cells (2,2) from Word document Tables 1-10
Dim wdDoc As Word.Document
Dim wdFileName As Variant
Dim TableNo As Integer 'number of tables in Word doc
Dim iTable As Integer 'table number index
Dim iRow As Long 'row index in Excel
Dim iCol As Integer 'column index in Excel
wdFileName = Application.GetOpenFilename("Word files (*.doc*),*.doc*", , _
"Browse for file containing table to be imported")
If wdFileName = False Then Exit Sub '(user cancelled import file browser)
Set wdDoc = GetObject(wdFileName) 'open Word file
With wdDoc
TableNo = wdDoc.tables.Count
If TableNo = 0 Then
MsgBox "This document contains no tables", _
vbExclamation, "Import Word Table"
ElseIf TableNo > 10 Then
TableNo = 10
'Else TableNo is actual number of tables between 1 and 9
End If
Range("A1") = "Table #"
Range("B1") = "Cell (2,2)"
For iTable = 1 To TableNo
With .tables(iTable)
'copy cell contents from Word table cells to Excel cells in column B and C
Cells(iTable + 1, "A") = iTable
Cells(iTable + 1, "B") = WorksheetFunction.Clean(.cell(2, 2).Range.Text)
End With
Next iTable
End With
Set wdDoc = Nothing
End Sub
以下是我想要实现的示例:
这是Word中的表格:
我希望将针对印度的单元格内容放入excel中的列中,如下所示:
任何帮助都将不胜感激。提前谢谢