Results 1 to 25 of 25

Thread: [RESOLVED] PowerPoint Image Control VBA

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Resolved [RESOLVED] PowerPoint Image Control VBA

    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.

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: PowerPoint Image Control VBA

    Set the picture via code

    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")
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Re: PowerPoint Image Control VBA

    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.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: PowerPoint Image Control VBA

    you could load the pictures on opening and unload on closing then no size increase
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Re: PowerPoint Image Control VBA

    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

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: PowerPoint Image Control VBA

    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?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Re: PowerPoint Image Control VBA

    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

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: PowerPoint Image Control VBA

    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
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Re: PowerPoint Image Control VBA

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

  10. #10
    Addicted Member
    Join Date
    Jan 2009
    Posts
    183

    Re: PowerPoint Image Control VBA

    Try this line:
    vb Code:
    1. 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.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Re: PowerPoint Image Control VBA

    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

  12. #12
    Addicted Member
    Join Date
    Jan 2009
    Posts
    183

    Re: PowerPoint Image Control VBA

    Quote Originally Posted by Khadafi View Post
    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
    Code:
    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:
    Code:
     oPPTShape.Fill.UserPicture "C:\Documents and Settings\Path\To\Image.jpg"
    where oPPTShape is a reference to the shape on your slide.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Re: PowerPoint Image Control VBA

    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

  14. #14
    Addicted Member
    Join Date
    Jan 2009
    Posts
    183

    Re: PowerPoint Image Control VBA

    Quote Originally Posted by Khadafi View Post
    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.

    Quote Originally Posted by Khadafi View Post
    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:
    Code:
    Slide14.Shapes("ShapeName").Fill.Solid
    Quote Originally Posted by Khadafi View Post
    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.

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Re: PowerPoint Image Control VBA

    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

  16. #16
    Addicted Member
    Join Date
    Jan 2009
    Posts
    183

    Re: PowerPoint Image Control VBA

    Quote Originally Posted by Khadafi View Post
    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.
    Code:
        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.

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Re: PowerPoint Image Control VBA

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

    Code:
    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
    Last edited by Khadafi; Dec 29th, 2009 at 06:35 PM.

  18. #18
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: PowerPoint Image Control VBA

    Quote Originally Posted by Khadafi View Post
    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

    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# (Check out how Mark did it in the last post...)
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Re: PowerPoint Image Control VBA

    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

    Code:
    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
    Last edited by Khadafi; Dec 31st, 2009 at 11:25 AM.

  20. #20
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: PowerPoint Image Control VBA

    In that case why don't you loop thru the relevant shapes?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Re: PowerPoint Image Control VBA

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

  22. #22
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: PowerPoint Image Control VBA

    Quote Originally Posted by Khadafi View Post
    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
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  23. #23

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    76

    Re: PowerPoint Image Control VBA

    Thanks for all the help, i got it working
    Thanks

  24. #24
    New Member
    Join Date
    Nov 2022
    Posts
    3

    Re: PowerPoint Image Control VBA

    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?
    Last edited by Learningtocode99; Nov 28th, 2022 at 02:43 PM. Reason: Not yet resolved

  25. #25
    Lively Member
    Join Date
    May 2021
    Posts
    95

    Re: [RESOLVED] PowerPoint Image Control VBA

    You should start a separate thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width