Solved

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

Posted on 2012-03-14
7
879 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
  • 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
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 the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now