Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-19
2
Medium Priority
?
4,355 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 500 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

715 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