Solved

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

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
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.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

617 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