resize graphics

B

Bill

I need to resize every graphics in a word documnet so that they are
75% wide. Can I do this in VBA
 
M

macropod

Hi Bill,

Yes, but 75% of what - the current image size, the original image size, margin width, something else?
 
M

macropod

Hi Bill,

You could use a macro like:

Sub ImageReformatter()
Dim oShp As Shape, iShp As InlineShape, sScale As Single
With ActiveDocument
sScale = 0.75
For Each oShp In .Shapes
With oShp
If .Type = msoLinkedPicture Or .Type = msoPicture Then
.ScaleHeight sScale, True
.ScaleWidth sScale, True
End If
End With
Next oShp
For Each iShp In .InlineShapes
With iShp
If .Type = wdInlineShapeLinkedPicture Or .Type = wdInlineShapePicture Then
.ScaleHeight = sScale * 100
.ScaleWidth = sScale * 100
End If
End With
Next iShp
End With
MsgBox "Finished Reformatting."
End Sub
 
B

Bill

Unfortunately I discovered that they as inserted into document as
links not embedded graphics. is there a way to programmatically
convert the to embedded graphics
 
M

macropod

Hi Bill,

In the code, change:
With oShp
to
With oShp
If .Type = msoLinkedPicture Then .Unlink

and
With iShp
to
With iShp
If .Type = wdInlineShapeLinkedPicture Then .Unlink
 
J

jeffstx3

How does one determine what the original size was from VBA? We can easily
see what the altered values are. Do we reverse calculate what the original
has to have been? Is that the only way? The problem is that the original
size often depends upon the screen resolution at the time of the graphic
insertion or update.

macropod said:
Hi Bill,

Yes, but 75% of what - the current image size, the original image size, margin width, something else?

--
Cheers
macropod
[Microsoft MVP - Word]


I need to resize every graphics in a word documnet so that they are
75% wide. Can I do this in VBA
 
M

macropod

Hi Jeff,

Yes, you can 'reverse calculate', using code like:
Sub GetImageSizes()
Dim oShp As Shape, iShp As InlineShape, sScale As Single
Dim sH As Single, sW As Single, tmpH As Single, tmpW As Single
Application.ScreenUpdating = False
With ActiveDocument
For Each oShp In .Shapes
With oShp
If .Type = msoLinkedPicture Or .Type = msoPicture Then
sH = .Height
sW = .Width
.ScaleHeight 1, True
.ScaleWidth 1, True
tmpH = .Height
tmpW = .Width
.Height = sH
.Width = sW
MsgBox "The picture named: " & .Name & " is" & vbCr & _
PointsToInches(sH) & " inches high, by" & vbCr & _
PointsToInches(sW) & " inches wide." & vbCr & _
vbCr & "It was originally " & vbCr & _
PointsToInches(tmpH) & " inches high, by" & vbCr & _
PointsToInches(tmpW) & " inches wide."
End If
End With
Next oShp
End With
Application.ScreenUpdating = True
End Sub

Note: I've only coded for 'floating' shapes. I'll leave it to you to extend the code to dealin with inline shapes.

--
Cheers
macropod
[Microsoft MVP - Word]


jeffstx3 said:
How does one determine what the original size was from VBA? We can easily
see what the altered values are. Do we reverse calculate what the original
has to have been? Is that the only way? The problem is that the original
size often depends upon the screen resolution at the time of the graphic
insertion or update.

macropod said:
Hi Bill,

Yes, but 75% of what - the current image size, the original image size, margin width, something else?

--
Cheers
macropod
[Microsoft MVP - Word]


I need to resize every graphics in a word documnet so that they are
75% wide. Can I do this in VBA
 

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