Solved

how can I insert a floating shape at a bookmark with vba 2003 MS Word

Posted on 2012-03-14
7
974 Views
Last Modified: 2013-06-23
how can I insert a floating shape at a bookmark with vba 2003 MS Word
0
Comment
Question by:Dov_B
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 37722710
Here is an example:
Dim sh As Shape
Dim rng As Range
Set rng = ActiveDocument.Bookmarks("bmk1").Range
Set sh = ActiveDocument.Shapes.AddShape(msoShapeOval, 10, 20, 150, 200, rng)

Open in new window

0
 

Author Comment

by:Dov_B
ID: 37722807
darn I meant a picutre I have the following and it dont work
Sub AddPictureAtBookMark3(bmname, picfile)
Selection.GoTo What:=wdGoToBookmark, Name:=bmname
Selection.InlineShapes.AddPicture FileName:= _
        picfile, LinkToFile:=False, _
        SaveWithDocument:=True
        ActiveDocument.InlineShapes(0).Select
  Selection.InlineShapes(Selection.InlineShapes.Count).ConvertToShape
  With ActiveDocument.Shapes(ActiveDocument.Shapes.Count)
  .Top = .Top + 40
  .Height = 50
  .Width = 50
  End With
End Sub

and nietther does this
Sub AddPictureAtBookMark(bmname, picfile)
With ActiveDocument.Shapes
Set myPicture = .AddPicture(picfile, _
LinkToFile = False, Savewithdcoument = True, _
Anchor:=ActiveDocument.Bookmarks(bmname).Range)
End With
End Sub
0
 

Author Comment

by:Dov_B
ID: 37722825
what I mean is that instaed of putting it at the bookmark it puts it at the top of the page
0
[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 37722918
Your first code refers to InLine shapes (i.e.not floating)

The shape will be displayed on the same page as the anchor. It's position on the page is determined by the top and left settings, so you would need to specify them, either in the AddPicture method or later:

Sub AddPictureAtBookMark(bmname, picfile)
    With ActiveDocument.Shapes
        Set myPicture = .AddPicture(picfile, _
                        LinkToFile = False, Savewithdcoument = True, _
                        Left:=100, Top:=100, _
                        Anchor:=ActiveDocument.Bookmarks(bmname).Range)
    End With
    myPicture.Left = 200
End Sub
0
 

Author Comment

by:Dov_B
ID: 37722934
Thank you so much for the explanation.
is it possible to get the left and top of the bookmark? you see I am trying to put the picutres very precisely under specific words. I do this by placing bookmarks at the words location
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 37724094
Thanks. It is possible to position a graphic relative to a range. However, it won't be fixed relative to the bookmark, so any change in pagination could move the bookmark, but not the graphic.
Sub AddShapeAtBookMark()
    Dim sh As Shape
    Dim rng As Range
    Set rng = ActiveDocument.Bookmarks("bmk1").Range

    Set sh = ActiveDocument.Shapes.AddShape(msoShapeRectangle, 0, 0, 30, 10, rng)
    
    sh.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
    sh.RelativeVerticalPosition = wdRelativeVerticalPositionPage
    sh.Left = rng.Information(wdHorizontalPositionRelativeToPage)
    sh.Top = rng.Information(wdVerticalPositionRelativeToPage) + 12
End Sub

Open in new window

0
 

Author Comment

by:Dov_B
ID: 39270189
Dear GrahamSkan,
I used the above code many times with amazing results but then. Iwas busy with other things for a few months. When I tried using that macro code again it totaly did not put the picture next to the bookmark at all?!!
Do you have any ideas on what the issue might be?
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

688 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