如何使用VBA删除Word中的单元格内容? [英] How to delete cell contents in Word with VBA?

查看:826
本文介绍了如何使用VBA删除Word中的单元格内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了VBA中表格单元格对象和选择对象的文档,但是在保留单元格本身的同时,我没有看到任何删除Word中单元格内容的方法.在Excel中看起来很容易,而在Word中看起来几乎是不可能的.

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?

推荐答案

这有效:

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

将删除整个单元格!

前者相当于选择一个单元格并按 Delete 键(清除内容但将单元格留在原处).后者等效于右键单击一个单元格,然后选择删除单元格..."(这将删除该单元格).

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).

这篇关于如何使用VBA删除Word中的单元格内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆