Share via

VBA - rotate or flip during addpicture

Anonymous
2016-10-11T15:23:26+00:00

I am struggling to find a method to addpicture and have it rotated 90deg to the left or flip it horizontally. The only way I can do it is to add the picture first, then use select to rotate it afterwards.

Set shpCanvasShapes = shpCanvas.CanvasItems

 With shpCanvasShapes

    .AddPicture FileName:=Pth & "img1.png", Left:=0, Top:=0, Width:=200, Height:=300

 End With

Also it does not like parentheses which I was hoping to allow me to tag on .IncrementRotation 90# 

 .AddPicture(FileName:=Pth & "img1.png", Left:=0, Top:=0, Width:=200, Height:=300)

How can this be done?

Appreciate any input. Thanks.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
  1. John Korchok 231.4K Reputation points Volunteer Moderator
    2016-10-11T19:13:39+00:00

    You can use a Set statement to assign the added picture to a Shape object, then pass additional formatting commands to it without selecting. This also shows the circumstance in which you use brackets for parameters:

    Sub RotatePic()

      Dim NewPic As Shape

      Pth = "I:"

      Set shpCanvas = Selection.ShapeRange

      Set shpCanvasShapes = shpCanvas.CanvasItems

      Set NewPic = shpCanvasShapes.AddPicture(FileName:=Pth & "Map.jpg", Left:=0, Top:=0, Width:=200, Height:=300)

      NewPic.Rotation = -90

    End Sub

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2016-10-12T15:39:21+00:00

    Thank you John.

    0 comments No comments