G
Guillermo
[Context: automating Excel from within Word]
Hello,
I want to copy a single column table from Word to a spreadsheet. I know that due to an
Excel feature (bug?), copied cells from a Word table are pasted in separate cells in
Excel if they contain line feeds. Doing it by hand, you can get around this by
doubleclicking on the spreadsheet before actually pasting the Word cell's content -
one by one.
Using the following code...
....
Sub DOCTable2XLS()
Dim appXLS As Excel.Application
Dim a As Integer
Dim b As Long
Dim c As Cell
Set appXLS = GetObject(, "Excel.Application")
a = appXLS.ActiveCell.Column
b = appXLS.ActiveCell.Row
'appXLS.Visible = True
For Each c In ActiveDocument.Tables(1).Columns(1).Cells
c.Select
Selection.Copy
appXLS.ActiveCell.PasteSpecial xlPasteValues
b = b + 1
appXLS.Cells(b, a).Activate
Next
End Sub
....
.... I do get the Word table copied to Excel, but only the first line of each Word cell.
I'd like to know if there's a method to tell Excel to "enter" (like you do when
pressing F2 or doubleclicking) each cell for editing before copying the Word cell
contents. Alternatively, I could replace each line feed in Word with a placeholder
like "~r~" and then replace it again in Excel with a manual line feed, but I don't
know how to do that in Excel either.
Hello,
I want to copy a single column table from Word to a spreadsheet. I know that due to an
Excel feature (bug?), copied cells from a Word table are pasted in separate cells in
Excel if they contain line feeds. Doing it by hand, you can get around this by
doubleclicking on the spreadsheet before actually pasting the Word cell's content -
one by one.
Using the following code...
....
Sub DOCTable2XLS()
Dim appXLS As Excel.Application
Dim a As Integer
Dim b As Long
Dim c As Cell
Set appXLS = GetObject(, "Excel.Application")
a = appXLS.ActiveCell.Column
b = appXLS.ActiveCell.Row
'appXLS.Visible = True
For Each c In ActiveDocument.Tables(1).Columns(1).Cells
c.Select
Selection.Copy
appXLS.ActiveCell.PasteSpecial xlPasteValues
b = b + 1
appXLS.Cells(b, a).Activate
Next
End Sub
....
.... I do get the Word table copied to Excel, but only the first line of each Word cell.
I'd like to know if there's a method to tell Excel to "enter" (like you do when
pressing F2 or doubleclicking) each cell for editing before copying the Word cell
contents. Alternatively, I could replace each line feed in Word with a placeholder
like "~r~" and then replace it again in Excel with a manual line feed, but I don't
know how to do that in Excel either.