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

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Converting a noninline shape to an inline shape (Word 2007)

    Author
    Topic
    #455282

    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

    Viewing 0 reply threads
    Author
    Replies
    • #1132586

      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.

      • #1132777

        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

        • #1132779

          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

          • #1132780

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

            Any ideas?

            Thanks!!
            Troy

            • #1132782

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

            • #1132878

              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

            • #1132879

              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.

            • #1132922

              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

            • #1132929

              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

              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

            • #2598811

              Hi,

              Please I want to convert all other types of shapes to regular shapes by making such modification

              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, msoAutoShape, msoFreeform, msoTextBox
              ActiveDocument.Shapes(i).ConvertToInlineShape
              End Select
              Next i

              End sub

              but doesn’t work

              Any fix please

    Viewing 0 reply threads
    Reply To: Converting a noninline shape to an inline shape (Word 2007)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: