Solved

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

Posted on 2012-03-14
7
917 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

There is a feature provided by MS Word that lets you create an Table of Contents for your Word document automatically. To use this feature for other documents there are two steps involved,   1.  Prepare your document for a table of contents (he…
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…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
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.

831 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