Solved

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

Posted on 2004-04-19
2
4,230 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
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 shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
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.

707 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

18 Experts available now in Live!

Get 1:1 Help Now