We help IT Professionals succeed at work.

Word VBA test for InlineShapes or ShapeRange

Fylar
Fylar asked
on
4,739 Views
Last Modified: 2010-05-18
Hi All.

I need an if statement to determine if the selected image is either an inline shape or a 'real' shape.
In the end I convert the inline shape to a real shape, but I need a test at the start of the macro so I don't preach to the converted. :)

Thanks.

Fylar
Comment
Watch Question

Author

Commented:
Perhaps I can add something to clarify this a little more...

What I want is something like this...

Sub convertAndMovePicture()
'####
'this needs to be performed only if it is an inline shape
If Selection is an Inlineshape then
    Selection.InlineShapes(1).ConvertToShape.Select
Endif

'####
'this needs to be performed in all cases
    Selection.ShapeRange.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
    Selection.ShapeRange.RelativeVerticalPosition = wdRelativeVerticalPositionPage
    Selection.ShapeRange.Left = CentimetersToPoints(5.6)
    Selection.ShapeRange.Top = CentimetersToPoints(4.12)
End Sub
Retired
CERTIFIED EXPERT
Top Expert 2012
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Fantastic.
I needed to modify it a little, as an InlineShape is not a ShapeRange (I think)
This is my final macro.
Sub movePicture()
    If Selection.InlineShapes.Count = 1 Then
       'this needs to be performed only if it is an inline shape
       Selection.InlineShapes(1).ConvertToShape.Select
    End If
    'this needs to be performed in  all cases
    If Selection.ShapeRange.Count = 1 Then
      Selection.ShapeRange.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
      Selection.ShapeRange.RelativeVerticalPosition = wdRelativeVerticalPositionPage
      Selection.ShapeRange.Left = CentimetersToPoints(5.6)
      Selection.ShapeRange.Top = CentimetersToPoints(4.12)
     Else
      MsgBox ("An Image was not selected")
     End If
End Sub

Thanks for your help. This is exactly what I was after.

Cheers,

Fylar
GrahamSkanRetired
CERTIFIED EXPERT
Top Expert 2012

Commented:
Thanks, especially for the feedback. That's always appreciated.

Author

Commented:
No problems. Thanks again for your help.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.