Solved

vba macro to insert floating picture into word at 50% size

Posted on 2004-04-19
2
4,247 Views
Last Modified: 2012-06-27
I have been manually cutting pictures out of paint, then paste them into word.  

I then right click, format picture > layout > in front of text > size > 50%

But I do this a lot, so I want a macro.  Unfortunatly, word xp doesn't record macro's for format picture commands.

I've done a little research and ran across

http://www.experts-exchange.com/Applications/MS_Office/Word/Q_20908966.html

several problems with that accepted answer.

#1, when I paste the picture into word, it does not go into the shapes collection.  I have to manually convert it to a "in front of text" before it goes into the shapes collection.


#2, when the code hits  Selection.ShapeRange.Height = 69.85, i get run-time error '70' permission denied.

Any ideas?

0
Comment
Question by:rberke
2 Comments
 
LVL 24

Accepted Solution

by:
R_Rajesh earned 125 total points
ID: 10864527
rberke,

this adds a new picture as a sape

Dim nShp As Shape
Set nShp = ActiveDocument.Shapes.AddPicture("C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\sunset.jpg")
nShp.ScaleHeight 0.5, True
nShp.ScaleWidth 0.5, True

this converts the first inlineshape to plain shape:

Dim nShp As Shape
Set nShp = ActiveDocument.InlineShapes(1).ConvertToShape
nShp.ScaleHeight 0.5, True
nShp.ScaleWidth 0.5, True

Rajesh
0
 
LVL 5

Author Comment

by:rberke
ID: 10865598
Thanks, that was all I needed.

I added paste and select logic and it seems to work fine.

Bob
Sub Macro4()

    Dim nShp As Shape
    Selection.PasteAndFormat (wdPasteDefault)
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Set nShp = Selection.InlineShapes(1).ConvertToShape
nShp.ScaleHeight 0.5, True
nShp.ScaleWidth 0.5, True
End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

867 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

24 Experts available now in Live!

Get 1:1 Help Now