Macro to insert image

Hello,

Looking to build a macro to insert a specific image into an absolute postion on a document - I will then assign to a button or whatever so the user can click this button and the image is placed onto the document.
Some of the documents are protected so the code needs to check this, unprotect if ness and then reprotect (no password, filling in forms)
sbsbatsAsked:
Who is Participating?
 
GrahamSkanConnect With a Mentor RetiredCommented:
This adds the picture as a shape which can be positioned on the page.

It uses a bookmark to determine the page.
Sub InsertPictureShape()
    Dim sh As Shape
    With ActiveDocument
        Set sh = .Shapes.AddPicture("C:\MyFolder\MyPicture.jpg", False, True, , , , .Bookmarks("bmpPicture").Range)
        sh.RelativeHorizontalPosition = wdRelativeHorizontalPositionLeftMarginArea
        sh.RelativeVerticalPosition = wdRelativeVerticalPositionTopMarginArea
        sh.Top = CentimetersToPoints(1.5)
        sh.Left = CentimetersToPoints(0.5)
    End With
End Sub

Open in new window

0
 
GrahamSkanRetiredCommented:
How do you define the absolute position?
0
 
sbsbatsAuthor Commented:
Good questions - margin? - VBA positioning? - never done it I just need to be able to place it in a specific location on the page (e.g. 05cm from left margin and 1.5cm from top margin)
0
 
GrahamSkanRetiredCommented:
This will add an in line picture at a bookmark.
Sub InsertInLinePictureAtBookmark()
    Dim ilsh As InlineShape
    With ActiveDocument
        Set ilsh = .InlineShapes.AddPicture("C:\MyFolder\MyPicture.jpg", False, True, .Bookmarks("bmpPicture").Range)
    End With
End Sub

Open in new window

0
 
sbsbatsAuthor Commented:
thanks for your help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.