I've got text in a Word document that needs to be turned into a table and then the second column of the table pasted into Excel. I'm doing all of this through a macro in Excel.
I run into a problem in red section. "sel.WholeStory" does highlight all of the text in Word. But for some reason it doesn't seem to recognize this. At the next line I get this error: "Run-time error 509: The TextToTable command is not available because no text is selected." But it is all selected! I've tried deselecting and reselecting again and that does no good. I've tried adding references to the Word document, even though I think "WordBasic" should be sufficient. The code works in Word.
Any ideas?
Thank you for any help.
(Word and Excel both 2007)
I run into a problem in red section. "sel.WholeStory" does highlight all of the text in Word. But for some reason it doesn't seem to recognize this. At the next line I get this error: "Run-time error 509: The TextToTable command is not available because no text is selected." But it is all selected! I've tried deselecting and reselecting again and that does no good. I've tried adding references to the Word document, even though I think "WordBasic" should be sufficient. The code works in Word.
Any ideas?
Rich (BB code):
Sub SSConvertToTable()
Dim wd As Object
Set wd = CreateObject("Word.Application")
wd.Visible = True
Dim doc As Object
Set doc = wd.Documents.Open("H:\SS_January31.docx")
Dim sel As Object
Set sel = wd.Selection
' In Word - Format text for table
'This part adds appropriate delimiters so the text can be
split into a two column table
' In Word - Turn to table
sel.WholeStory
WordBasic.TextToTable ConvertFrom:=3, NumColumns:=2
(Word and Excel both 2007)