VBA知道段落是否为IMAGE

时间:2018-11-13 10:04:15

标签: vba ms-word

我有以下代码:

For Each DocPara In ActiveDocument.Paragraphs
    If (DocPara.style = "Title 1") Then
        ...
    Else

        (if DocPara is LIST then)
            ...
        (else if DocPara is TABLE then)
            ...
    End If
Next DocPara

有没有办法知道当前段落是否为图像。

1 个答案:

答案 0 :(得分:1)

当前段落不能“是”图像,因为任何图像始终是段落中的字符或锚定到 段落中。有必要计算该段范围内/所附图片的数量。

因此,一个段落不能只是一幅图像,它总是至少包含一个字符串字符(ANSI 13,段落标记),并且除了图像之外,还可以包含无限个数字。

Word支持两种图像:InlineShapesShapes。第一个与字符相同;后者具有自动换行格式。

使用文本换行格式设置的图像可能看起来像在“段落中”,但不是,甚至可能没有锚定在出现该段落的段落中。因此,当所讨论的图像类型为Shape时,实际上不可能通过查询Paragraph对象来确定段落中是否有图像。

下面是确定段落中是否InlineShape和是否将Shapes固定在段落中的代码。根据您的疑问句表​​达方式,我希望您的图片是InlineShapes ...

Dim rngPara as Word.Range
Set rngPara = DocPara.Range
If rngPara.InlineShapes.Count > 0 Then 'the paragraph contains an image
If rngPara.ShapeRange.Count > 0 Then 'an image is anchored to the paragraph