• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Macro question

Hi,

The following code works well for what I need but I have one question/inquery - it relies on a bookmark on the page where the image is to be inserted - can I modify this and use something like activeDocument so I don't have to use bookmarks?
0
sbsbats
Asked:
sbsbats
  • 4
  • 2
1 Solution
 
sbsbatsAuthor Commented:
Sub InsertPictureShape()
Dim sh As Shape
With ActiveDocument
  Set sh = .Shapes.AddPicture("C:\image\sbs.png", False, True, , , , .Bookmarks("logo").Range)
    sh.RelativeHorizontalPosition = wdRelativeHorizontalPositionLeftMarginArea
    sh.RelativeVerticalPosition = wdRelativeVerticalPositionTopMarginArea
    sh.Top = CentimetersToPoints(0.8)
    sh.Left = CentimetersToPoints(12.2)
    End With
End Sub
0
 
GrahamSkanRetiredCommented:
The code uses ActiveDocument.Bookmarks("logo").Range. That's how the With block works.

You have to specify where you want the picture. If you don't know it in terms of the Word object, can you describe in words where you need the picture?
0
 
sbsbatsAuthor Commented:
on the active page - i.e if the doc has more than one page then the page with the cursor on it
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
GrahamSkanRetiredCommented:
Try this.
Sub InsertPictureShape()
Dim sh As Shape
With ActiveDocument
  Set sh = .Shapes.AddPicture("C:\image\sbs.png", False, True, , , , Selection.Paragraphs(1).Range)
    sh.RelativeHorizontalPosition = wdRelativeHorizontalPositionLeftMarginArea
    sh.RelativeVerticalPosition = wdRelativeVerticalPositionTopMarginArea
    sh.Top = CentimetersToPoints(0.8)
    sh.Left = CentimetersToPoints(12.2)
    End With
End Sub

Open in new window

0
 
sbsbatsAuthor Commented:
Graham, you are a legend - thanks for your help with this
0
 
sbsbatsAuthor Commented:
exactly what I needed
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.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now