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
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » 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
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
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.
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
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
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
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications