excel and word

K

Kilo Bravo

Sub parseWordTable()

Dim filename As String
Dim i As Integer
Dim myRange As Range
Set myRange = Range("a1:b20")

' Open the file dialog
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
.Show
filename = .SelectedItems(1)
End With
Word.Documents.Open filename

For i = 1 To ActiveDocument.Tables(1).Rows.Count
myRange(i, 1) = ActiveDocument.Tables(1).Cell(i, 1)
Next

End Sub

The question is how do I get rid of the none text characters that show up in myRange?
--
K.Brown
/*****************************************************************************
To the optimist, the glass is half full.
To the pessimist, the glass is half empty.
To the engineer, the glass is twice as big as it needs to be.
******************************************************************************/
 
J

Jezebel

Word table cells always contain two extra characters, even if the cell is
empty -- a final paragraph mark and an end-of-cell marker: chr(13)chr(7) --
so you need to strip these out

MyText = ActiveDocument.Tables(1).Cell(i, 1).range
MyText = left(MyText, len(MyText)-2)

Separately, you need to be careful about the type of Range you're dealing
with. Word ranges and Excel ranges are not interchangable. If you're trying
to copy the Word table into Excel, it's usually simpler just to copy and
paste the table as a whole -- Excel is smart enough to deal with the
superfluous characters itself. Alternatively, copy the table into a variant
dimensioned as an array, then assign that to the Excel range.






Sub parseWordTable()

Dim filename As String
Dim i As Integer
Dim myRange As Range
Set myRange = Range("a1:b20")

' Open the file dialog
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
.Show
filename = .SelectedItems(1)
End With
Word.Documents.Open filename

For i = 1 To ActiveDocument.Tables(1).Rows.Count
myRange(i, 1) = ActiveDocument.Tables(1).Cell(i, 1)
Next

End Sub

The question is how do I get rid of the none text characters that show up in
myRange?
--
K.Brown
/***************************************************************************
**
To the optimist, the glass is half full.
To the pessimist, the glass is half empty.
To the engineer, the glass is twice as big as it needs to be.
****************************************************************************
**/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top