Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
developmental2@walla.com - 01 Oct 2005 18:44 GMT
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
Tony Jollans - 01 Oct 2005 18:56 GMT
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

> Hi all,
>
[quoted text clipped - 45 lines]
>
> thanks
developmental2@walla.com - 06 Oct 2005 23:49 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.