Re: Pastespecial problem

Tech-Archive recommends: Fix windows errors by optimizing your registry



Piou2fois was telling us:
Piou2fois nous racontait que :

> Hi all
>
> I was looking for a script able to decrease the word file size with a
> lot of pictures.
> I found the possibility to use cut and pastespecial as jpg
> here is the script i use :
>
> Function cut_paste_as_jpg(image As InlineShape) As Boolean
> image.Select
> question = (MsgBox("Do you want toconvert this picture?",
> vbYesNoCancel, "Convert to jpg"))
> Select Case question
> Case vbYes
> Selection.CopyAsPicture
> Selection.PasteSpecial Link:=False, _
> DataType:=15, _
> Placement:=wdInLine
> cut_paste_as_jpg = True
> Case vbNo
> cut_paste_as_jpg = True
> Exit Function
> Case vbCancel
> cut_paste_as_jpg = False
> End Select
> End Function
>
> Sub jpg_mass_convert()
> Dim image As InlineShape
> For Each image In ActiveDocument.InlineShapes
> If Not cut_paste_as_jpg(image) Then Exit Sub
> Next image
> End Sub
>
> This script is great for all inlineshape and you can win size
>
> Big problem is that with this method, each picture has 2 problems
> -a 1px black border below and right of the picture
> -paste as something which is not inlineshape (picture is in edit mode)
>
> do you think there is something to do avoid these two problems,
> because for the first point it is horrible to see that, and for the
> second one, I cannot put border on the picture with macro.
>

I do not get the border problem you described (Word 2003). Maybe it has to
do with your pictures themselves.

Try the following code for handling both inline and floating pictures. Make
sure that you handle floating pictures first because even though the jpg are
pasted as inline and will behave as such, Word will see them as floating
shapes (They are shape fields). So, if you handle the floating shapes after
the inline ones, the inline that were converted the first time around will
be converted again.

Also, remember that if you convert a floating shape to an inline one, it
will move from its floating position to the first character position in the
paragraph were it will be inline based on the paragraph that used to hold
the floating shape anchor before the conversion.

Finally, I had to delete the inline/floating shapes, otherwise they were all
doubled up...

'_______________________________________
Option Explicit

'_______________________________________
Function cut_paste_as_jpg(image As Object) As Boolean

Dim question As Variant

image.Select
question = (MsgBox("Do you want to convert this picture?", _
vbYesNoCancel, "Convert to jpg"))
Select Case question
Case vbYes
Selection.CopyAsPicture
Selection.Delete
Selection.PasteSpecial Link:=False, _
DataType:=15, _
Placement:=wdInLine
cut_paste_as_jpg = True
Case vbNo
cut_paste_as_jpg = True
Case vbCancel
cut_paste_as_jpg = False
End Select

End Function
'_______________________________________

'_______________________________________
Sub jpg_mass_convert()
Dim StartRange As Range
Dim image As InlineShape
Dim pix As Shape

Set StartRange = Selection.Range
Selection.Collapse

For Each pix In ActiveDocument.Shapes
If pix.Type = msoPicture Then
If Not cut_paste_as_jpg(pix) Then Exit Sub
End If
Next

For Each image In ActiveDocument.InlineShapes
If Not cut_paste_as_jpg(image) Then Exit Sub
Next

StartRange.Select

End Sub
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@xxxxxxxxxxxxxxxxxxxxxxx
Word MVP site: http://www.word.mvps.org


.


Quantcast