СообЧа > База Знаний > Программирование > Visual Basic

Вопрос

Как перекинуть таблицу из Word в Excel?

Ответ

Начиная с Office 2000 появляются вложенные таблицы, нужно учесть.

Private Sub GetParagraps(ByVal objParagraps As Word.Paragraphs)
On Error GoTo Check:
Dim objParagraph As Word.Paragraph
Dim blnTableComplete As Boolean
Dim iParagraph As Long
   For iParagraph = 1 To objParagraps.Count
   Set objParagraph = objParagraps.Item(iParagraph)
   If objParagraph.Range.Tables.Count > 0 Then
If blnTableComplete = False Then GetTable objParagraph.Range.Tables(1)
       blnTableComplete = True
       Else
      blnTableComplete = False
       End If
   Next
   Set objParagraph = Nothing
   Exit Sub
Check:
   …
   Resume Next
End Sub

Private Sub GetTable(ByVal tblCurrent As Word.Table)
Dim CurrentRow As Word.Row
Dim CurrentCell As Word.Cell
Dim i As Long, j As Long
On Error GoTo Check:
   
   For i = 1 To tblCurrent.Rows.Count
   Set CurrentRow = tblCurrent.Rows.Item(i)
          …
  For j = 1 To CurrentRow.Cells.Count
    Set CurrentCell = CurrentRow.Cells.Item(j)
          …
       Next
   Next
   
   Set CurrentRow = Nothing
   Set CurrentCell = Nothing
Exit Sub
Check:
   …
   Resume Next
End Sub

Андрей



Copyright © 2000-2004 Сообщество Чайников
Контактная информация