Insert All Pictures In Folder Excel VBA Macro

Поделиться
HTML-код
  • Опубликовано: 23 июл 2024
  • Excel macro/VBA code available in this post: excelmacroclass.blogspot.com/...
    In a previous video, we saw how to insert a picture from the web in Excel. We can insert a local picture using the same method, just replacing the URL with the file name and drive path where is located. In this video, we see how to insert all the pictures in a given folder into Excel using VBA macros. The macro inserts the pictures in a given cell or range and resizes them accordingly. We can also decide whether to insert the source information or just make an independent copy of the pictures.
    Find many other macro examples and Excel VBA learning materials (including the Excel VBA Guide for Beginners and Excel VBA Objects Guide for Intermediate) in the blog spot: excelmacroclass.blogspot.com
    And yet, if you want more, you can find various Excel applications of different nature in the other blogs of the Excel Macro Mania saga:
    Excel Macro Fun (excelmacrofun.blogspot.com/)
    Excel Macro Business (excelmacrobusiness.blogspot.com/)
    Excel Macro Sports (excelmacrosports.blogspot.com/)

Комментарии • 7

  • @hoangminh8466
    @hoangminh8466 4 месяца назад +1

    This works for me. Thank you very much.

  • @MohAboAbdo
    @MohAboAbdo 11 месяцев назад

    Thank you so much, Sir.

  • @shadow_gaming_sk
    @shadow_gaming_sk 11 месяцев назад

    Excellent video

  • @KyleAnderson2301
    @KyleAnderson2301 2 месяца назад

    How would I have only certain images inserted from the file folder selected?

    • @ExcelMacroMania
      @ExcelMacroMania  2 месяца назад

      One way is to add the list of names of those images that you want to add in a range maybe in other worksheet, and then add a condition inside the Do loop to check if the file has that name. You can check that adding another loop through the list of names (in the range or put into an array), or putting all of them into a string with Join and check if the file name is there with InStr. For that last option it would look like:
      If InStr(MyFile, TargetFiles) > 0 Then 'insert image
      where the TargetFiles string could be built with Join, for example for 10 image names in range A1:A10:
      TargetFiles = Join(Application.Transpose(Sheet2.Range("A1:A10").Value), ",")
      Another possibility is having the full name with path for the images you want to add and loop through the list while simply insert one a time. This way it doesn't matter if they are in the same folder or not, as long as you provide the path/folder info.

  • @megapower3239
    @megapower3239 5 месяцев назад

    how can we make the width of the pictures bigger?

    • @ExcelMacroMania
      @ExcelMacroMania  5 месяцев назад

      The picture fits the size of the cell. That's why we set the row height and then get the size first with properties Left, Top, Width, and Height. You can also set the column width of the cell before adding the picture with Cells(r, 2).ColumnWidth = 10 for example. If you want to change the width of the picture without changing the width of the cell (the picture will overflow the cell), you need to assign the picture to an object variable (Set pic = ActiveSheet.Shapes.AddPicture(myPic,msoFalse, msoTrue,x,y,....) and then modify the width with pic.Width = 200