# Visual Basic > Office Development >  [RESOLVED] PowerPoint Image Control VBA

## Khadafi

Hi, I want to use Image Controls in PowerPoint to load images, however I do not want the images to be embedded, and just be linked so that the PowerPoint does not increase a lot in size.

Any help would be much appreciated.

Thank You.

----------


## Siddharth Rout

Set the picture via code



```
'~~> Image1 is the name of the image control
'~~> Replace "C:\1.bmp" with actual path and filename
Set Image1.Picture = LoadPicture("C:\1.bmp")
```

----------


## Khadafi

Hi, thanks for the reply.
That is the code i have been trying earlier, using that code increases my powerpoint presentation file size by around 12 mb with just one picture. I just want a to link the pictures to the filepath so that the size of the presentation does not increase.
Thank You.

----------


## westconn1

you could load the pictures on opening and unload on closing then no size increase

----------


## Khadafi

Hi, thanks for the reply.
I have considered that, but i need the images to be loaded from the first slide.
Can i run a macro as soon as the presentation file is opened (to load the images), and then run another macro when the presentation is closed (to unload the images).
Thanks

----------


## westconn1

> Can i run a macro as soon as the presentation file is opened (to load the images), and then run another macro when the presentation is closed (to unload the images).


i guess so, does powerpoint have any events?

----------


## Khadafi

Hi, what do you mean by events?.
isnt there any code i could use that just links the image controls to the image file without the size increasing,
or is there any other method of putting images into powerpoint without actually embedding the images.
Thanks

----------


## westconn1

not that i know of with an image control, i assume you can insert an object or hyperlink, that may work with as a link to an image


> Hi, what do you mean by events?.


code that runs automatically when the program performs operation, like presentation open or application close
they are generally in dropdown boxes at the top of the code window

----------


## Khadafi

Hi, thanks for the reply.
I'll just have to do it without vba, and insert pictures and select link instead of embed.
Thanks

----------


## MarkWalsh

Try this line:
vb Code:
ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:="C:\Documents and Settings\Path\To\Image.jpg", LinkToFile:=msoTrue, SaveWithDocument:=msoFalse)
This should add the picture linked instead of embedded. Be sure to supply your own path to your file, and change the reference to 'ActiveWindow.Selection.SlideRange.Shapes' to the slide that you want to add the picture to.

----------


## Khadafi

Hi, thanks for the reply.
I have tried using this code, but think i am doing something wrong.
Can i use imagecontrols with this code, or just shape objects. 
Code you create like an example for me. say i want to use link a picture ("C:\Documents and Settings\Path\To\Image.jpg" to a shape object called "Image1" on slide14, what is the code i would have to use,
Sorry for any inconvenience.
Thank You

----------


## MarkWalsh

> Hi, thanks for the reply.
> I have tried using this code, but think i am doing something wrong.
> Can i use imagecontrols with this code, or just shape objects. 
> Code you create like an example for me. say i want to use link a picture ("C:\Documents and Settings\Path\To\Image.jpg" to a shape object called "Image1" on slide14, what is the code i would have to use,
> Sorry for any inconvenience.
> Thank You


Are you using a PPT shape, or a placeholder, or an Image Control from the VBA toolbox?

If it's an image control, I believe you would load the picture like this


```
oPPTImageControl.Picture = LoadPicture( "C:\Documents and Settings\Path\To\Image.jpg")
```

where oPPTImageControl is a reference to the control on your slide.


If you're trying to add the image into the background fill for a shape, then this should work:


```
 oPPTShape.Fill.UserPicture "C:\Documents and Settings\Path\To\Image.jpg"
```

where oPPTShape is a reference to the shape on your slide.

----------


## Khadafi

Hi, i got the following code you suggested to work:  oPPTShape.Fill.UserPicture "C:\Documents and Settings\Path\To\Image.jpg"
but i had to change it to:
Slide14.Shapes("ShapeName").Fill.UserPicture "C:\Documents and Settings\Path\To\Image.jpg"

This only increases my file size by a bit, which i didnt really want but i can make do with.
However i was wondering is there a way in which i could remove the picture fill so that the presentation returns back to its original size using code.

Also you suggested "LinkToFile:=msoTrue, SaveWithDocument:=msoFalse)" in a earlier code, but i could not get this to work, maybe this will only link the file and not increase the size.

Thank You For All Your Help So Far

----------


## MarkWalsh

> Hi, i got the following code you suggested to work:  oPPTShape.Fill.UserPicture "C:\Documents and Settings\Path\To\Image.jpg"
> but i had to change it to:
> Slide14.Shapes("ShapeName").Fill.UserPicture "C:\Documents and Settings\Path\To\Image.jpg"


Yes, my original code was using 'oPPTShape'. You would need to substitute a reference to your shape, or use a variable.




> This only increases my file size by a bit, which i didnt really want but i can make do with.
> However i was wondering is there a way in which i could remove the picture fill so that the presentation returns back to its original size using code.


You would set the fill of the shape to something other than a picture, e.g. a solid fill:


```
Slide14.Shapes("ShapeName").Fill.Solid
```




> Also you suggested "LinkToFile:=msoTrue, SaveWithDocument:=msoFalse)" in a earlier code, but i could not get this to work, maybe this will only link the file and not increase the size.
> 
> Thank You For All Your Help So Far


What version of PPT are you using? In version 2003, it doesn't look like you can link a picture as a fill for a shape. At least that option doesn't appear to be in the interface (you can only use it as a link if it is placed directly on the slide). It does appear to be possible in version 2007, but I haven't checked to see if the code is the same.

----------


## Khadafi

Hi, 
if i use: Slide14.Shapes("ShapeName").Fill.Solid
what do i need to put after the solid, what can i use as solids
can i use a colour?
Thank You

----------


## MarkWalsh

> Hi, 
> if i use: Slide14.Shapes("ShapeName").Fill.Solid
> what do i need to put after the solid, what can i use as solids
> can i use a colour?
> Thank You


Sure, you can set it to any color you want.


```
    With Slide14.Shapes("ShapeName").Fill
        .Visible = msoTrue
        .Solid
        .ForeColor.RGB = RGB(255, 0, 0)
        .Transparency = 0#
    End With
```

Look up the 'FillFormat Object' and 'FillFormat Object Members' in the VBA help for more.

----------


## Khadafi

Hi, thanks thats working great.
Is there any way that i can use



```
With Slide14.Shapes("ShapeName").Fill
        .Visible = msoTrue
        .Solid
        .ForeColor.RGB = RGB(255, 0, 0)
        .Transparency = 0#
```

with many shapes, for example, Shape1, Shape2 ... at one time, without having that code each time for each shape.

Thank You

----------


## Siddharth Rout

> Hi, thanks for the reply.
> That is the code i have been trying earlier, using that code increases my powerpoint presentation file size by around 12 mb with just one picture. I just want a to link the pictures to the filepath so that the size of the presentation does not increase.
> Thank You.


Sorry was out of town so couldn't reply... I am still on holiday  :Big Grin: 

Well the problem is not because you are linking but because you are not compressing the picture after inserting in the slide... after you have finished linking the filepath to the image, you need to compress the picture by setting the *.Transparency* to *0#*  :Wink:  (Check out how Mark did it in the last post...)

----------


## Khadafi

Hi, thanks for the reply, thats working great.

i am using
Slide14.Shapes("ShapeName").Fill.UserPicture "C:\Documents and Settings\Path\To\Image.jpg"
to add the images

and I am using the code below to hide / remove the images when needed



```
With Slide14.Shapes("ShapeName").Fill
        .Visible = msoTrue
        .Solid
        .ForeColor.RGB = RGB(255, 0, 0)
        .Transparency = 0#
```

but i would like to use it with many shapes, for example, to hide Shape1, Shape2 ... at one time, without having that code each time for each shape.

Thank You

----------


## Siddharth Rout

In that case why don't you loop thru the relevant shapes?

----------


## Khadafi

Hi, can you give me an example of how to do that.
Thanks

----------


## Siddharth Rout

> Hi, can you give me an example of how to do that.
> Thanks


Sorry, I missed this post...

See if this helps... (see post 8)

http://www.vbforums.com/showthread.php?t=574485

----------


## Khadafi

Thanks for all the help, i got it working
Thanks

----------


## Learningtocode99

Hi, I would like to do something similar. I am trying to code so that an image shows up in my image control space but I want to display a different image in that same control space each time one of my precoded labels shows up. 

To elaborate: I am attempting to create a bingo game however because its for kids I am using pictures instead of numbers. I have already gotten the various picture calls to call randomly but I want it to show up bigger beside the space that lays them all out as theyve been called.

Is there a way to do this?

----------


## Dan_W

You should start a separate thread.

----------

