PDA

View Full Version : Fit a picture in a graphic



Ingemar
08-21-2016, 12:17 AM
Hi,

I want to fit a picture in a graphic with VBA-Code. For better unterstanding I have attached an example.
16912
lg, Ingemar

gmaxey
08-21-2016, 06:30 AM
What steps did you take to create the original graphic/picture pair?

Ingemar
08-21-2016, 12:17 PM
Hi Greg,

I work with a word template, which is filled with data from an access database. This is my code in access:
Set objMyShape = docNew.Shapes("Photo")
objMyShape.Fill.UserPicture D:\MyPhotos\picture2.jpg

The shape "Photo" is a rectangle in the word template, such like the graphic in the example file. But when I fill the rectangle with the picture, it is deformed.:crying:

Have you any idea?

Greetings from Austria,
Ingemar

gmaxey
08-21-2016, 01:27 PM
Well that doesn't help much, but maybe you can adapt something like this to suit your need:


Sub Test()
Dim objMyShape
Dim oRng As Range
Set objMyShape = ActiveDocument.Shapes(1)
Set oRng = objMyShape.TextFrame.TextRange
oRng.InlineShapes.AddPicture FileName:= _
"D:\MyPhotos\picture2.jpg" _
, LinkToFile:=False, SaveWithDocument:=True
End Sub