Reputation: 7529
I'm trying to write a very basic macro in VB for Microsoft Word, but I don't have the required knowledge.
I simply need to do two things:
I can do the first task via the record new macro feature but I am unable to select move a picture while in recording mode so I need some VB code for this.
I already have this, so how do I move/resize the image?
Selection.InlineShapes.AddPicture FileName:= _
"C:\Users\***\Pictures\**.jpg" _
, LinkToFile:=False, SaveWithDocument:=True
Upvotes: 4
Views: 56499
Reputation: 17049
The AddPicture function has a number of parameters which include width and height which you can use to resize the image to the desired size.
Please see an example below:
Sub InsertImage()
Dim imagePath As String
imagePath = "C:\\picture.jpg"
ActiveDocument.Shapes.AddPicture FileName:=imagePath, _
LinkToFile:=False, _
SaveWithDocument:=True, _
Left:=-5, _
Top:=5, _
Anchor:=Selection.Range, _
Width:=20, _
Height:=20
End Sub
Additionally, have a look at this msdn article for an explanation of the AddPicture() function as well as the list of available parameters which you can pass to it.
Upvotes: 8