how to tell if hilighted area contains images or other stuff, in Word

  • Thread starter Thread starter LJ
  • Start date Start date
L

LJ

hi,

I would like be able to tell with VBA code whether the current
selection is an image(s) OR is a section that user has dragged the
mouse around and happens to contain an image(s).

(basically, the code should be able to distinguish whether the
selection has non-images, like just some plain text, or is the
selection all InlineShapes or Shapes?)

my attempt as follows, which doesn't work quite right when the
selection happens to have one image, along with some plain text. is
there a better way?

Dim iSectionsCount As Integer =
app.ActiveWindow.Selection.Range.Sections.Count
Dim iInlineShapesCount As Integer =
app.ActiveWindow.Selection.InlineShapes.Count
Dim iShapeRangeCount As Integer =
app.ActiveWindow.Selection.ShapeRange.Count

bJustImages = False
If True Then
If iSectionsCount = iInlineShapesCount Then
bJustImages = True
ElseIf iInlineShapesCount = 0 Then
If iSectionsCount = iShapeRangeCount Then
bJustImages = True
End If
End If
End If


thanks in advance,
lj
 
the code below works (better), but I am still open to good ideas...
thanks,
lj

Dim iInlineShapesCount As Integer =
app.ActiveWindow.Selection.InlineShapes.Count
Dim iShapeRangeCount As Integer =
app.ActiveWindow.Selection.ShapeRange.Count

bJustImages = False
If iInlineShapesCount >= 1 Then
If app.ActiveWindow.Selection.Text.Equals("/") Then
bJustImages = True
End If
ElseIf iInlineShapesCount = 0 Then
If iShapeRangeCount > 0 Then
bJustImages = True
End If
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top