Paste image resizing and moving images using Microsoft word macro

I am trying to write a very simple macro in VB for Microsoft Word, but I do not have the necessary knowledge.

I just need to do two things:

  • Insert image from file
  • Move it to the upper right corner and resize it.

I can complete the first task by recording a new macro, but I cannot choose to move the image during recording, so I need a 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 
+4
source share
1 answer

The AddPicture function has a number of parameters that include the width and height that you can use to resize the image to fit it.

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 

Also, see this msdn article for an explanation of the AddPicture () function, as well as a list of available options that you can go through to it.

+6
source

Source: https://habr.com/ru/post/1402699/


All Articles