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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With