+ Reply to Thread
Results 1 to 6 of 6

Is there a Macro that can insert multiple photos to a selected range of cells.

  1. #1
    Registered User
    Join Date
    02-03-2016
    Location
    Tustin, California
    MS-Off Ver
    2011
    Posts
    4

    Is there a Macro that can insert multiple photos to a selected range of cells.

    Hi All, I am brand new to the forum and using macros. I have already dabbled a little with codes to insert photos in multiple cells. But the codes I have found only allow me to insert photos to one column or row at a time. Id like to select a range of cells and fill them with images from a folder. Is it possible?

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Is there a Macro that can insert multiple photos to a selected range of cells.

    It is definitely possible. I think you have not received any responses because your question has lots of possible solutions depending on what you truly want. For example, how do you want to handle the size of the pictures - do you want to shrink the photos so that they fit into the cells or do you want to resize the cells so that the photo fits to its original dimensions, or do you want to standardize on an image size? Regardless, to get you started, you should review the different methods and variables for the Shape class. You can use the Object Browser in your VB shell or search on the web. And, to go through your range, you would need to use a loop, probably something like
    Please Login or Register  to view this content.
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  3. #3
    Registered User
    Join Date
    02-03-2016
    Location
    Tustin, California
    MS-Off Ver
    2011
    Posts
    4

    Re: Is there a Macro that can insert multiple photos to a selected range of cells.

    Hi Pauleyb,
    Thank you for you help with my macro inquiry. I am okay with the image re sizing to the selected cell. I like the uniform look of all the images even if they are stretched a little. Here is the macro I have been using. It works great except that I am limited to inserting multiple images into one column. Id like to be able to select a range of cells and insert multiple images and have them automatically re size to the cell. Can you help me expand upon this macro?

    Sub InsertPictures()
    'Update 20140513
    Dim PicList() As Variant
    Dim PicFormat As String
    Dim Rng As Range
    Dim sShape As Shape
    On Error Resume Next
    PicList = Application.GetOpenFilename(PicFormat, MultiSelect:=True)
    xColIndex = Application.ActiveCell.Column
    If IsArray(PicList) Then
    xRowIndex = Application.ActiveCell.Row
    For lLoop = LBound(PicList) To UBound(PicList)
    Set Rng = Cells(xRowIndex, xColIndex)
    Set sShape = ActiveSheet.Shapes.AddPicture(PicList(lLoop), msoFalse, msoCTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height)
    xRowIndex = xRowIndex + 1
    Next
    End If
    End Sub

  4. #4
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Is there a Macro that can insert multiple photos to a selected range of cells.

    I would recommend you step through the code and understand what each line and variable is doing. Many of your questions are answered in the code above. For example, the line where you 'Set Rng=...' is which cell the picture is going to be placed. Using my sample above, you would just pass the 'cell' variable in place of Rng.
    However, there are still other issues, such as what happens if the person selects more pictures than there are cells in your range? Your code above loops for every file selected, but you will also need to loop through your selected range, and those may not match. How would you want to handle that?

    Play with the code above and step through it. This is a rough change that will step through your selection, but without any real error checking:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-03-2016
    Location
    Tustin, California
    MS-Off Ver
    2011
    Posts
    4

    Re: Is there a Macro that can insert multiple photos to a selected range of cells.

    Holy Cow!!!That worked perfectly! Your the best Pauleyb, I cant thank you enought!

  6. #6
    Registered User
    Join Date
    02-03-2016
    Location
    Tustin, California
    MS-Off Ver
    2011
    Posts
    4

    Re: Is there a Macro that can insert multiple photos to a selected range of cells.

    Hi Pauleyb,
    I'd like to expand upon the macro you help me create to insert photos into cells. I would like to now know if it is possible to have the photos skip and column and a row when auto filling. Id like to do this so that there is a space in between the photos. Is it possible.?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Insert multiple photos into excel macro
    By whan714 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-22-2015, 06:00 PM
  2. resize, insert, and arrange multiple photos
    By opusarlo in forum Excel General
    Replies: 1
    Last Post: 02-18-2015, 05:50 PM
  3. VBA Insert all Photos from folder - photos not lined up w/ cell borders in older versions
    By jaimelwilson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2014, 02:26 PM
  4. Insert multiple Photos MACRO
    By yazl in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-19-2014, 10:26 AM
  5. Insert Photos Macro Help
    By garrett1483 in forum Excel General
    Replies: 0
    Last Post: 07-23-2013, 03:40 AM
  6. Resize and insert multiple photos
    By latausm in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-07-2011, 11:34 AM
  7. Insert multiple photos in excel
    By shanelawler in forum Excel General
    Replies: 0
    Last Post: 03-08-2010, 06:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1