Setting background to "No fill"

K

Kate Moncrieff

Hi,

Can anyone tell me how I can make the background of an
inserted image transparent?

I can do it manually in Word by right-clicking on the
background (of the ungrouped image), choosing the "Format
Autoshape..." option and changing the Fill colour on
the "Colours and Lines" page to "No fill". However, when
I try and record these actions, they seem to be ignored.

Thanks for any tips!
Kate
 
D

DeeJee

Is it possible to make this kind of shape transparent?
Also, do you have any idea why I can't record the actions
in Word?

Don't know why you can't record this but this is the macro
that was created here to set to no fill for the selected shape.
But you only need the first line of code. See end of mail.

Sub Macro1()
Selection.ShapeRange.Fill.Visible = msoFalse
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.Transparency = 0#
Selection.ShapeRange.Line.Weight = 0.75
Selection.ShapeRange.Line.DashStyle = msoLineSolid
Selection.ShapeRange.Line.Style = msoLineSingle
Selection.ShapeRange.Line.Transparency = 0#
Selection.ShapeRange.Line.Visible = msoTrue
Selection.ShapeRange.Line.ForeColor.RGB = RGB(0, 0, 0)
Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Rotation = 0#
Selection.ShapeRange.Left = 241.75
Selection.ShapeRange.Top = 61.75
Selection.ShapeRange.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionColumn
Selection.ShapeRange.RelativeVerticalPosition = _
wdRelativeVerticalPositionParagraph
Selection.ShapeRange.Left = CentimetersToPoints(6.03)
Selection.ShapeRange.Top = CentimetersToPoints(-0.32)
Selection.ShapeRange.LockAnchor = False
Selection.ShapeRange.WrapFormat.AllowOverlap = True
Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
Selection.ShapeRange.WrapFormat.DistanceTop = CentimetersToPoints(0)
Selection.ShapeRange.WrapFormat.DistanceBottom = CentimetersToPoints(0)
Selection.ShapeRange.WrapFormat.DistanceLeft = CentimetersToPoints(0.32)
Selection.ShapeRange.WrapFormat.DistanceRight = CentimetersToPoints(0.32)
Selection.ShapeRange.WrapFormat.Type = 3
Selection.ShapeRange.ZOrder 4
End Sub

Try
Sub Macro1()
Selection.ShapeRange.Fill.Visible = msoFalse
End Sub
Hope this can help.
 
J

JGM

Hi Kate

When you use
LinkToFile:=False, SaveWithDocument:=True
.Shapes(.Shapes.Count).Ungroup
you ungroup the picture you just inserted. This
ungrouping generates new shapes and add to the shape
collection, or so you would think. Actually, if you
insert a WMF file and then ungroup it, the result is not
a bunch of new shapes, but a bunch of autoshapes, and the
TransparentBackground property does not apply to an
autoshape (you have to set the fillcolor to tranparant).
And you cannot ungropup a JPG...

Anyway, even if it worked, when you use
With .Shapes(.Shapes.Count)
right after ungrouping, you would have no idea which
shape from the group you are selecting (.Shape.Count
would represent the total number of shapes, and after
ungrouping, which one (From the group) is the last (or
highest) number?).

So the question is: Why do you ungroup?
If it is to set the background to transparent, then, and
only if it is a simple picture, do not ungroup it and try
using
BlueScreen = RGB(255, 255, 255).
I tried it with simple BMP, JPG and WMF pictures, and it
worked. But often pictures, especially WMF pictures from
the Office Clip Art library, are drawn with a bunch of
superposed pictures, so there is no real "Background" to
speak of...

Finally, you cannot record your action if you click about
the screen with the mouse when you try to select
pictures. You have to find ways to do your actions
through the keyboard, which can be difficult when dealing
with picture because you cannot navigate through the
pictures in a document with the keyboard. So, you have to
select the shape you want, then run the macro recorder,
use the keyboard and then modify the result in the VBA
editor window... To deal with shapes you have to know
either their index number in the shape collection, or
their individual names.
What I have done in the past is use AutoText to store
pictures I wanted the user to use, and I gave them names
before (by using VBA and the Name property), so I could
control the selection from the code by using their names,
and checking for errors if the name was not found in the
document, meaning the picture is not there...

HTH
Cheers!
 
D

DeeJee

Finally, you cannot record your action if you click about
the screen with the mouse when you try to select
pictures. You have to find ways to do your actions
through the keyboard

Normally yes, but I tried it in WordXP
with the mouse and it recorded without problems,
starting with the shape selected.
 
W

Word Heretic

G'day "DeeJee" <deejee@skynet.be>,

not passing any judgement on the method suggested, just merely noting
the macro recorder aint worth POO when working out Word's workings lol
:)


DeeJee said:
Normally yes, but I tried it in WordXP
with the mouse and it recorded without problems,
starting with the shape selected.

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email (e-mail address removed)
Products http://www.geocities.com/word_heretic/products.html

Replies offlist may require payment.
 
K

Kate Moncrieff

Hi JGM, Hi DeeJee,

Thanks to both of you I’ve managed to find a way to do it
(and also learnt a few things).

My program is now like this…

' Count exisiting shapes in the document
NExisitingShapes = ActiveDocument.Shapes.Count

' Insert and ungroup the graph
With ActiveDocument
.Shapes.AddPicture FileName:=vrtSelectedItem,
LinkToFile:=False, SaveWithDocument:=True
.Shapes(.Shapes.Count).Ungroup
End With

' Set the background to transparent
BackgroundShapeIndex = NExisitingShapes + 1
ActiveDocument.Shapes(BackgroundShapeIndex).Fill.Visible =
msoFalse

The purpose of the macro I’m writing is to insert graphs
generated in a standard way into a document and do as much
processing as possible - resizing, repositioning,
ungrouping etc. - so that the graph is ready for the user
to make manual adjustments such as changing the size of
the graph title.

I’ve found it’s safe to assume that, after the ungrouping,
the (auto)shape that contains the background has the
lowest index of all the new shapes that have just been
inserted. (When I posted the question I was assuming for
some reason that it was the new shape with the highest
index.)

Thanks again!!
Kate
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top