Picture Sizing

K

Kerry

Hi

I want a procedure in my template which simplifies the
entering of pictures into a table, inserting them at the
correct size. The procedure is in place but I cannot
understand the meaurement units being used and cannot
find any info in help about it - I have to have a set
picture size but I can't seem to change the measurement
unit.

Please find the code below - the size I want for the
photos is 6.5cm height x 5.5cm width but the code only
seems to want to work on numbers in the hundreds, does
anyone have any ideas what units are being used and how I
can convert them to centimetres in the code or just how
to work it out manually to enter the correct number.
Many Many thanks

InsertPhoto:
Dim Myrange As Range

With Options
.PictureEditor = "Microsoft Word"
.PictureWrapType = wdWrapMergeFront
.MeasurementUnit = wdCentimeters
'measurement unit doesn't seem to make any diff
End With

If Selection.Information(wdWithInTable) Then
With Dialogs(wdDialogInsertPicture)
If .Show Then
Set Myrange = Selection.Cells(1).Range
If Myrange.InlineShapes.Count > 0 Then
With Myrange.InlineShapes(1)
.LockAspectRatio = msoTrue
.Height = 6.5 '138.5
.Width = 5.5 '147.4
End With
Else
With Myrange.ShapeRange
.LockAspectRatio = msoTrue
.Width = 5.5 '147.4
.Left = wdShapeCenter
.WrapFormat.Type = wdWrapThrough
' .WrapFormat.Side = wdWrapBoth
.LockAnchor = False
.IncrementLeft 1#
.IncrementTop 20#
End With
End If
End If
End With
End If
 
K

Kerry

I thought I would post my answer for anyone else to look
at. I eventually found this information - really really
helpful:--

Determining Picture Size in VBA
Word keeps quite a bit of information together about the
images that you insert in your documents. This
information is necessary so that Word knows how to size,
position, and display images. If you want to find out
more information about the images in your document, then
you need to know something about how Word stores the
information.

Images are stored as either of two types of graphic
objects: regular shapes or inline shapes. Regular shapes
are those that reside on the drawing layer, as opposed to
inline shapes, which reside in the text layer. Both types
of objects are stored with different object collections.
Regular shapes are in the Shapes collection, and inline
shapes are stored in the InlineShapes collection. To
access information about the objects, you just need to
use a little VBA.

The following VBA macro will work in Word 2000 to create
a document that displays the size of all the graphics
objects within a document, in both points and pixels:

Sub FigureInfo()
Dim iShapeCount As Integer
Dim iILShapeCount As Integer
Dim DocThis As Document
Dim J As Integer
Dim sTemp As String

Set DocThis = ActiveDocument
Documents.Add

iShapeCount = DocThis.Shapes.Count
If iShapeCount > 0 Then
Selection.TypeText Text:="Regular Shapes"
Selection.TypeParagraph
End If
For J = 1 To iShapeCount
Selection.TypeText Text:=DocThis.Shapes(J).Name
Selection.TypeParagraph
sTemp = " Height (points): "
sTemp = sTemp & DocThis.Shapes(J).Height
Selection.TypeText Text:=sTemp
Selection.TypeParagraph
sTemp = " Width (points): "
sTemp = sTemp & DocThis.Shapes(J).Width
Selection.TypeText Text:=sTemp
Selection.TypeParagraph
sTemp = " Height (pixels): "
sTemp = sTemp & PointsToPixels(DocThis.Shapes(J).Height,
True)
Selection.TypeText Text:=sTemp
Selection.TypeParagraph
sTemp = " Width (pixels): "
sTemp = sTemp & PointsToPixels(DocThis.Shapes(J).Width,
False)
Selection.TypeText Text:=sTemp
Selection.TypeParagraph
Selection.TypeParagraph
Next J

iILShapeCount = DocThis.InlineShapes.Count
If iILShapeCount > 0 Then
Selection.TypeText Text:="Inline Shapes"
Selection.TypeParagraph
End If
For J = 1 To iILShapeCount
Selection.TypeText Text:="Shape " & J
Selection.TypeParagraph
sTemp = " Height (points): "
sTemp = sTemp & DocThis.InlineShapes(J).Height
Selection.TypeText Text:=sTemp
Selection.TypeParagraph
sTemp = " Width (points): "
sTemp = sTemp & DocThis.InlineShapes(J).Width
Selection.TypeText Text:=sTemp
Selection.TypeParagraph
sTemp = " Height (pixels): "
sTemp = sTemp & PointsToPixels(DocThis.InlineShapes
(J).Height,
True)
Selection.TypeText Text:=sTemp
Selection.TypeParagraph
sTemp = " Width (pixels): "
sTemp = sTemp & PointsToPixels(DocThis.InlineShapes
(J).Width,
False)
Selection.TypeText Text:=sTemp
Selection.TypeParagraph
Selection.TypeParagraph
Next J
End Sub

This macro only works in Word 2000 onwards because Word
97 does not recognize the PointsToPixels statement. If
you remove the lines that use this statement (or create
your own PointsToPixels function), then the macro
will work just fine under Word 97.

Note that the macro returns the names of regular shapes,
but not the names of inline shapes. The reason for this
is that Word doesn't maintain the names of inline shapes.
When you insert a regular shape in your document (well,
on the drawing layer), then Word assigns a name to the
shape, such as Rectangle 2 or Oval 3.
 

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