K
kbmurphy
Hello all,
I've got a VBA function that attempts to take a word table, select it,
cut it, and then create a Word OLE object where the table used to be,
then pastes the table into the Word OLE. I need this for a program I
work with that doesn't play nice with Word tables.
The code is below, and it works in Word 2003, but it will not work for
all tables in a larger document. I'm not sure why, and was wondering
if anyone had any ideas.
Thanks in advance!
Sub ConvertTablesToOLE()
'
'Move to top of document
Selection.GoTo What:=wdGoToPage, which:=wdGoToFirst
'Get count of tables
Dim tCount As Integer
Dim i As Integer
tCount = ActiveDocument.Tables.Count
i = 1
While i <= tCount
Selection.GoTo What:=wdGoToTable, which:=wdGoToNext 'go to first cell
of next table
Selection.MoveUp Count:=1
Selection.EndKey
Selection.TypeParagraph
Selection.MoveDown Count:=1
Selection.Tables(1).Range.Select
Selection.Cut
Selection.MoveUp Count:=1
'Create OLE, paste into it
Selection.InlineShapes.AddOLEObject ClassType:="Word.Document.8",
FileName _
:="", LinkToFile:=False, DisplayAsIcon:=False
ActiveWindow.Selection.Paste
ActiveWindow.Close
i = i + 1
tCount = ActiveDocument.Tables.Count 'We now have one less table, so
tCount gets updated
Wend
End Sub
I've got a VBA function that attempts to take a word table, select it,
cut it, and then create a Word OLE object where the table used to be,
then pastes the table into the Word OLE. I need this for a program I
work with that doesn't play nice with Word tables.
The code is below, and it works in Word 2003, but it will not work for
all tables in a larger document. I'm not sure why, and was wondering
if anyone had any ideas.
Thanks in advance!
Sub ConvertTablesToOLE()
'
'Move to top of document
Selection.GoTo What:=wdGoToPage, which:=wdGoToFirst
'Get count of tables
Dim tCount As Integer
Dim i As Integer
tCount = ActiveDocument.Tables.Count
i = 1
While i <= tCount
Selection.GoTo What:=wdGoToTable, which:=wdGoToNext 'go to first cell
of next table
Selection.MoveUp Count:=1
Selection.EndKey
Selection.TypeParagraph
Selection.MoveDown Count:=1
Selection.Tables(1).Range.Select
Selection.Cut
Selection.MoveUp Count:=1
'Create OLE, paste into it
Selection.InlineShapes.AddOLEObject ClassType:="Word.Document.8",
FileName _
:="", LinkToFile:=False, DisplayAsIcon:=False
ActiveWindow.Selection.Paste
ActiveWindow.Close
i = i + 1
tCount = ActiveDocument.Tables.Count 'We now have one less table, so
tCount gets updated
Wend
End Sub