I am trying to manipulate Word tables from Excel. The general problem I am encountering has already been addressed by Microsoft here:
tldr: Merged Cells in Word Tables require a work around to select entire rows to delete.
I used and customized the following code snippet:
Sub RemoveTableBorders()
ActiveDocument.Tables(1).Cell(1, 1).Select
With Selection
.SelectRow
.Cells.Borders.Enable = False
End With
End Sub
However I get an 438 Error, pointing to the .SelectRow
command. VBA tells me that this is not a valid command for an object. It feels like when I use the With Selection
command, Excel does not recognize that I am trying to write to word, as .selectrow
is a Word command. Therefore I am trying to include another pointer in the selection like this:
Sub RemoveTableBorders()
ActiveDocument.Tables(1).Cell(1, 1).Select
With ActiveDocument.Selection
.SelectRow
.Cells.Borders.Enable = False
End With
End Sub
I can not provide reproducible code.
I think the answer to the following question also solves my problem: If I have two open instances of Office programs, how can I tell which selection (Excel or Word) should be manipulated?
Selection
exists in the Excel object model, and would be fully-qualified asWith Excel.Application.Selection
, since Excel is your host application: you have to qualify it if you need it to refer to anything in the Word object model..SelectRow
is documented to throw an error if the selection isn't in a table, are you sure the preceding.Select
call is putting the selection where you need it to be? – Mathieu Guindon