?
Solved

Macro to insert image

Posted on 2011-10-05
5
Medium Priority
?
372 Views
Last Modified: 2012-05-12
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)
0
Comment
Question by:sbsbats
  • 3
  • 2
5 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36920719
How do you define the absolute position?
0
 

Author Comment

by:sbsbats
ID: 36920784
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36920790
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
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 36921075
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
 

Author Closing Comment

by:sbsbats
ID: 36921195
thanks for your help
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question