问题描述
我想用Excel来表达一个表,我正在使用Damon的以下代码来使用VBA实现相同的功能。这样做时,我需要帮助将给定单词表中由长下划线/长下划线分隔的文本传输到excel中的列。
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
以下是我要实现的示例:
任何帮助将不胜感激。在此先感谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)