Avatar of sbsbats
sbsbats
Flag for New Zealand asked on

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?
Visual Basic Classic

Avatar of undefined
Last Comment
sbsbats

8/22/2022 - Mon
sbsbats

ASKER
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
GrahamSkan

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?
sbsbats

ASKER
on the active page - i.e if the doc has more than one page then the page with the cursor on it
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
GrahamSkan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
sbsbats

ASKER
Graham, you are a legend - thanks for your help with this
sbsbats

ASKER
exactly what I needed