Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-03-14
7
Medium Priority
?
1,072 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
Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 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 October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free 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

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…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
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:
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

636 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