?
Solved

Macro question

Posted on 2011-10-06
6
Medium Priority
?
247 Views
Last Modified: 2012-08-13
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?
0
Comment
Question by:sbsbats
  • 4
  • 2
6 Comments
 

Author Comment

by:sbsbats
ID: 36927742
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
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36927781
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?
0
 

Author Comment

by:sbsbats
ID: 36927818
on the active page - i.e if the doc has more than one page then the page with the cursor on it
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 36927872
Try this.
Sub InsertPictureShape()
Dim sh As Shape
With ActiveDocument
  Set sh = .Shapes.AddPicture("C:\image\sbs.png", False, True, , , , Selection.Paragraphs(1).Range)
    sh.RelativeHorizontalPosition = wdRelativeHorizontalPositionLeftMarginArea
    sh.RelativeVerticalPosition = wdRelativeVerticalPositionTopMarginArea
    sh.Top = CentimetersToPoints(0.8)
    sh.Left = CentimetersToPoints(12.2)
    End With
End Sub

Open in new window

0
 

Author Comment

by:sbsbats
ID: 36928140
Graham, you are a legend - thanks for your help with this
0
 

Author Closing Comment

by:sbsbats
ID: 36928142
exactly what I needed
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

830 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