如何使用宏删除Word文档中的所有文本?

问题描述:

我想删除Word文档中的所有文本,并留下图像/嵌入文件如何使用宏删除Word文档中的所有文本?

我知道这应该很容易,但不能在网络上的一个很好的例子。

文字类型的wdSelectionNormal

所以,如果你迭代throught的文档中的所有字符并删除“字符”选中时是2型。它会做的伎俩。

这不应该真的很快,但它的工作。

这个例子来响应简单的情况:

Dim curCharIndex As Integer 
Dim charCount As Integer 
curCharIndex = 1 
charCount = ActiveDocument.Characters.Count 

While curCharIndex <= charCount 
    ActiveDocument.Characters(curCharIndex).Select 
    If Selection.Type = wdSelectionNormal Then 
     Selection.Delete 
     charCount = charCount - 1 
    Else 
     'Skip it 
     curCharIndex = curCharIndex + 1 
    End If 
Wend