.Addpicture to Word Document: Invalid property assignment.
I am trying to add an image to an MS-Word document using VBA from MS-Access. It works, but when I try to set the position as well, I get a runtime error.
Here is the line of code that works.
objShapes.AddPicture FileName:=strCompleteImagePath, LinkToFile:=False
Per MSDN , the syntax .AddPicture
is -
expression .AddPicture(Filename, LinkToFile, SaveWithDocument, Left, Top, Width, Height)
I tried:
objShapes.AddPicture strCompleteImagePath, True, True, 100, 100 , 70 , 70
and
objShapes.AddPicture FileName:=strCompleteImagePath, _
LinkToFile:=False, _
SaveWithDocument:=False, _
Left:=100, _
Top:=100, _
Width:=70, _
Height:=70
But I am getting error messages "incorrect number of paddings or invalid property assignment"
Is there something I'm blind about? Is it because of MS-Access?
I am taking the path to a graphic file from an MS-Access database by opening a MS-Word document and inserting an image in the middle of the document ... so I need to set its position, Is there no way to do this in one operation as .AddPicture
it seems promising?
The MSDN example in the documentation adds an image to a canvas element, not directly to a collection of shapes. Have you tried this? Shapes.AddPicture
The description is pretty self explanatory:
Adds an image to the drawing canvas . Gets a Shape object that represents the image and adds it to the CanvasShapes collection.
Dim canvas As Shape
Set canvas = ActiveDocument.Shapes.AddCanvas(Left:=100, Top:=100, Width:=70, Height:=70)
Dim pic As Shape
Set pic = canvas.CanvasItems.AddPicture(FileName:=path, LinkToFile:=False, SaveWithDocument:=True)