How to delete cell contents in Word with VBA?

别来无恙 提交于 2019-12-10 03:59:58

问题


I've looked at the documentation for table cell objects and selection objects in VBA, and I didn't see any way to delete cell contents in Word while retaining the cell itself. It looks like doing so is easy in Excel, and next to impossible in Word.

Some cells I need to do this for will contain text, others will contain text form fields. Any ideas?


回答1:


This works:

ActiveDocument.Tables(1).Cell(1, 2).Select
Selection.Delete

This deletes the cell contents but leaves the empty cell behind.

I understand your dismay, because oddly, the above does not do the same as

ActiveDocument.Tables(1).Cell(1, 2).Delete

which deletes the entire cell!

The former is the equivalent of selecting a cell and pressing the Delete key (which clears the contents but leaves the cell in place). The latter is the equivalent of right-clicking a cell and choosing "Delete cells..." (which deletes the cell).



来源:https://stackoverflow.com/questions/5878294/how-to-delete-cell-contents-in-word-with-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!