Results 1 to 10 of 10
  1. #1
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Converting a noninline shape to an inline shape (Word 2007)

    Is there a way in VBA to to change a graphic that is "In front of text" to "In line with text" and put it on the paragraph to which it is/was anchored?

    Thanks!!
    Troy

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Converting a noninline shape to an inline shape (Word 2007)

    The ConvertToInlineShape method of a Shape object converts the shape to an inline shape, and places it as near as possible to where it was.

  3. #3
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Converting a noninline shape to an inline shape (Word 2007)

    Hans,
    That seems to mostly work. Thanks!!

    I used the following code, mostly straight from the online help:

    Dim s As Shape

    For Each s In ActiveDocument.Shapes
    s.Select
    s.ConvertToInlineShape
    ' s.Select
    Next s


    However, after running it through my document, at least part way, I get an error:

    Run-time error '4120'

    Bad Parameter

    Any ideas what this means?

    Thanks!!
    Troy

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Converting a noninline shape to an inline shape (Word 2007)

    When altering all objects in a collection, it's usually best to loop backwards because you're altering the collection itself. And it isn't necessary to select shapes in order to convert them. So:

    Dim i As Integer
    For i = Activedocument.Shapes.Count To 1 Step -1
    ActiveDocument.Shapes(i).ConvertToInlineShape
    Next i

  5. #5
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Converting a noninline shape to an inline shape (Word 2007)

    Sounds like reasonable advice. However, I am still getting the same error.

    Any ideas?

    Thanks!!
    Troy

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Converting a noninline shape to an inline shape (Word 2007)

    I think we'd have to see a document in which the error occurs.

  7. #7
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Converting a noninline shape to an inline shape (Word 2007)

    Just found some additional information. This method seems to have done fine on graphics, but hiccuping at drawing objects like lines created inside Word.

    Does that make any sense or give anyone an idea? Can these be skipped somehow?

    Thanks!!
    Troy

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Converting a noninline shape to an inline shape (Word 2007)

    Try this modified version:

    Sub Convert2Inline()
    Dim i As Integer
    For i = ActiveDocument.Shapes.Count To 1 Step -1
    Select Case ActiveDocument.Shapes(i).Type
    Case msoEmbeddedOLEObject, msoLinkedOLEObject, _
    msoLinkedPicture, msoOLEControlObject, msoPicture
    ActiveDocument.Shapes(i).ConvertToInlineShape
    End Select
    Next i
    End Sub

    It only tries to convert some specific shape types to inline. You can add or remove types from the list.

  9. #9
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Converting a noninline shape to an inline shape (Word 2007)

    This works wonderfully!! Thanks!!

    Now just one more thing (and you knew there would be, right?). I still need to deal with these Word drawing items. The way I deal with them will probably different each time, so it will be a manual process.

    What I would like help in is a macro I can run to find and select each of these items. Is there a way to ignore all other shape types, and only find and select these items you generate from the Drawing toolbar in Word?

    Just to be clear. I just want something to find the next item (allowing me to start wherever I am at in the document and look forward for the item, select it, and then stop. I'll take it from there.

    Thanks for so willingly sharing your expertise!!
    Troy

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Converting a noninline shape to an inline shape (Word 2007)

    You can loop through the shapes as in my previous reply and look at their type. The ones you create from the Drawing toolbar are:

    msoAutoShape
    msoFreeForm
    msoLine
    msoTextBox
    msoTextEffect

    To select the first shape of one of these types after the selection, you can use
    <code>
    Sub GetNextShape()
    Dim shp As Shape
    Dim shpNext As Shape
    Dim lngPos As Long
    Dim lngMin As Long
    lngPos = Selection.End
    lngMin = 1000000000
    For Each shp In ActiveDocument.Shapes
    If shp.Anchor.Start > lngPos Then
    Select Case shp.Type
    Case msoAutoShape, msoFreeform, msoLine, msoTextBox, msoTextEffect
    If shp.Anchor.Start < lngMin Then
    lngMin = shp.Anchor.Start
    Set shpNext = shp
    End If
    End Select
    End If
    Next shp
    If shpNext Is Nothing Then
    MsgBox "No shape found", vbExclamation
    Else
    shpNext.Select
    End If
    End Sub</code>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •