Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

877 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