solution: how to make a macro that converts a picture to floating & tight


D

developmental2

Hi all,

Gave up on this a few years ago, today tried again and it worked
(word 2000)

if you paste an image in Word, using EDIT > Paste or with the INSERT >
PICTURE menu from some jpg or other image file,
it comes as an inline image. To turn it into a more convenient object
with text floating on all sides and zero border, (the way I prefer
things) it takes a procedure of several arduous clicks (if you have to
it on 40 pictures in one document!)

So I made a macro that reduces this to one click:
you select the image you want to convert and then click on the macro
icon, it does the rest.

What it does is equivalent to:

Right click on image > Format Object
Layout > Tight
Advanced > Distance from text, Top: 0, Bottom: 0, Left: 0, Right 0
and close the window.


if you want to use it make sure it is connected to an icon in the
toolbar.

Sub ConvertPic()
'
' ConvertPic Macro, recorded on Word 2000 (may not work on other
' versions, haven't tried it
'
With Selection.InlineShapes(1).ConvertToShape

.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapBoth
.WrapFormat.DistanceTop = CentimetersToPoints(0)
.WrapFormat.DistanceBottom = CentimetersToPoints(0)
.WrapFormat.DistanceLeft = CentimetersToPoints(0)
.WrapFormat.DistanceRight = CentimetersToPoints(0)
.WrapFormat.Type = wdWrapTight
End With

End Sub


hope this helps someone.
Of course this is freeware, so no responsibility for any harm or losses
caused by this code.

thanks
 
Ad

Advertisements

T

Tony Jollans

For those who are interested ..

In Word 97, pictures are pasted as floating objects.
In Word 2000 they are pasted in-line with text.
In Word XP and 2003 there is an option under Tools > Options so you can
decide which you want.

Enjoy,
Tony
 
Ad

Advertisements

D

developmental2

A better set of Macros (also useful for Word XP, haven't tried with 97)

' the sub below can handle both a floating and an inline image.
' this macro is intended to be linked to an icon on the toolbar:
' then:
' selecting an inline or floating image and then clicking on the icon
' will convert it to Tight + margins of zero (both are NOT default
' neither in Word 2000 nor in XP) which is very useful to me.
' Tight means that the Text floats around the image
' the default is that the entire block of text is pushed to the next
line(s), and tight corrects this.


Sub FormatPic()
'
' FormatPic Macro
' automatically formats selected inline picture
' as floating + tight + no margin
On Error GoTo errmsg


If TypeName(Selection.InlineShapes(1)) = "InlineShape" Then

With Selection.InlineShapes(1).ConvertToShape

.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapBoth
.WrapFormat.DistanceTop = CentimetersToPoints(0)
.WrapFormat.DistanceBottom = CentimetersToPoints(0)
.WrapFormat.DistanceLeft = CentimetersToPoints(0)
.WrapFormat.DistanceRight = CentimetersToPoints(0)
.WrapFormat.Type = wdWrapTight


End With


GoTo ExitMacro

End If

AbnormalAlready_Floating:

If TypeName(Selection.ShapeRange(1)) = "Shape" Then


With Selection.ShapeRange(1)

.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapBoth
.WrapFormat.DistanceTop = CentimetersToPoints(0)
.WrapFormat.DistanceBottom = CentimetersToPoints(0)
.WrapFormat.DistanceLeft = CentimetersToPoints(0)
.WrapFormat.DistanceRight = CentimetersToPoints(0)
.WrapFormat.Type = wdWrapTight
End With

End If

'

ExitMacro:

Exit Sub

errmsg:

If Err.Number = 5941 Then
Resume AbnormalAlready_Floating
Else
' if shape is already floating (but not tight etc) then don't convert
but
' do all other formats

MsgBox ("To use the 'eye' function, you have to first click on an
inline or floating picture, " & _
vbCrLf & "then click this function and it will convert the picture
to floating+tight and zero margins around it.")
End If

Resume ExitMacro

End Sub


' and the sub below makes sure an image is inserted as floating
' (but not Tight + margins 0) in Word 2000. As mentioned,
' in word 97/xp this is already the default.

Sub InsertPicture()
With Dialogs(wdDialogInsertPicture)

.FloatOverText = True
.Show


End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top