"Barbara" wrote:
> I am working on a macro to format graphics. (I owe it mainly to one of the
> Word MVPs, but I have forgotten exactly where I found it. I am grateful to
> the author, whoever it was.)
>
> The macro starts by checking whether a floating shape, in-line shape, or
> neither is selected. The in-line case is the one where I need some help. I
> want to convert it to a floating shape and specify some layout settings. That
> part is working fine. I also want to check whether the shape is in an
> otherwise empty paragraph and, if so, delete the paragraph, leaving the shape
> anchored to the preceding paragraph.
>
> My current strategy is:
>
> If an in-line shape is selected, then,
> If the paragraph where the selection starts contains two characters
> (namely, the shape and the paragraph break),
> move the shape up one paragraph,
> delete the now-empty paragraph
> end if
> convert to a floating shape
> end if
> etc.
>
Here is one way of doing it:
Dim inlShConvert As InlineShape
Dim ShpConverted As Shape
If Selection.Type = wdSelectionInlineShape Then
With Selection.Range.Paragraphs(1)
If .Range.Characters.Count = 2 Then
.Previous.Range.Characters(1).FormattedText = _
.Range.Characters(1).FormattedText
.Range.Delete
Set inlShConvert = .Previous.Range.Characters(1).InlineShapes(1)
Else
Set inlShConvert = Selection.InlineShapes(1)
End If
End With
Set ShpConverted = inlShConvert.ConvertToShape
With ShpConverted
.WrapFormat.Type = wdWrapTight
'Other Manipulations
End With
Else
MsgBox "The selection is not an inline shape.", _
vbExclamation, "No Shape"
End If
End Sub