Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Shape Size in Word VBA

Status
Not open for further replies.

stubdba

Programmer
Mar 1, 2013
3
Hello
I'm trying to set the shape size of a picture in my header on a landscape page but I just can't get the code to change the size.

If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="land"
Selection.Range.InsertAutoText
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
With Selection.ShapeRange
.Height = 2.79
.Width = 26.6
End With


All I'm wanting to to do is when I insert a landscape page in my document I want to call the autotext for the landscape image (this bits works) and then increase the size of the image from it's portrait size which is 2.78W 18W 32%

Any help would be brilliant as I've spent days trying to get it to work.
 
Word VBA Help said:
ShapeRange Collection Object
Represents a shape range, which is a set of shapes on a document. A shape range can contain as few as one shape or as many as all the shapes in the document.

If you want to change the size of a SHAPE then you need to manipulate the SHAPE object, not the ShapeRange object that the shape is in.
 
Thank you for the response - how do i select the shape object on the activeheader?
 
I have now managed to select the shape but it sets the size to "tiny"

How do I define that this is in CM?

Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
With Selection.InlineShapes(1)
.Height = 2.79
.Width = 26.6
End With
 
Word VBA Help said:
Height, Width Properties

The height or width, in points, of an object.


Word VBA Help said:
point
A point is 1/72 inch. Font sizes are usually measured in points.

So if you are thinking inches, multiply your numbers by 72.
 
Ah, you are thinking in cm. So multiply by 28.35. That's 72/2.54.
 
Stubda: Where is you header is this shape going? It appears you've used the macro recorder to record a series of steps that involve using the mouse to move around and delete something that was already there before inserting the new shape via your autotext. All of this can be done much more efficiently without selecting anything.

As for mintjulep's:
So multiply by 28.35. That's 72/2.54
It's actually smarter to use:
.Height = CentimetersToPoints(2.79)
.Width = CentimetersToPoints(18)
That way, you can let Word do the conversions of units you're familiar with while you concentrate on other aspects of the project.

Cheers
Paul Edstein
[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top