Discussion:
Word 2007 VBA - Positionierung eines Shapes zentriert in Bezug auf die Seitengröße
(zu alt für eine Antwort)
Alexander Kerensky
2010-10-04 10:04:06 UTC
Permalink
Hallo,

ich möchte ein Bild zentriert in Bezug auf die Seitengröße in der
Kopfzeile erstellen (quasi als Hintergrundbild). Das Problem dabei ist
dass sich das Shape immer am Seitenrand orientiert. Es soll aber immer
gleich aussehen, egal welche Seitenränder eingestellt sind.

Mein Code:

Set shp = ActiveDocument.Shapes.AddPicture( _
FileName:=strBild, Anchor:=rng, LinkToFile:=False,
SaveWithDocument:=True, Left:=19.25, Top:=199.85)

With shp
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.RelativeHorizontalSize = wdRelativeHorizontalSizePage
.RelativeVerticalSize = wdRelativeVerticalSizePage
End With
Bernhard Sander
2010-10-06 10:01:23 UTC
Permalink
Hallo Alexander,
Post by Alexander Kerensky
Hallo,
ich möchte ein Bild zentriert in Bezug auf die Seitengröße in der
Kopfzeile erstellen (quasi als Hintergrundbild). Das Problem dabei ist
dass sich das Shape immer am Seitenrand orientiert. Es soll aber immer
gleich aussehen, egal welche Seitenränder eingestellt sind.
Set shp = ActiveDocument.Shapes.AddPicture( _
FileName:=strBild, Anchor:=rng, LinkToFile:=False,
SaveWithDocument:=True, Left:=19.25, Top:=199.85)
With shp
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.RelativeHorizontalSize = wdRelativeHorizontalSizePage
.RelativeVerticalSize = wdRelativeVerticalSizePage
End With
.RelativeHorizontalSize hat nichts mit .RelativeHorizontalPosition zu tun
sondern arbeitet mit .WidthRelative zusammen.
Dagegen benötigt .RelativeHorizontalPosition weitere Angaben in .Left
(in der Vertikalen gilt Entsprechendes).

Probier's mal damit:

With shp
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Left = wdShapeCenter
.Top = wdShapeCenter
End With

Gruß
Bernhard Sander

Loading...