Results 1 to 3 of 3

insert images form subfolders

Threaded View

  1. #1
    Registered User
    Join Date
    03-25-2016
    Location
    Mumbai
    MS-Off Ver
    Window 2016
    Posts
    2

    insert images form subfolders

    i am new in marco please help me for insert images folder as well subfolders i have minimum 40 folder as well subfolders i need to insert images with excel cell name without .jpg extension

    refer below macro this is work only in folder but i have subfolders images also.

    Please help me thanks in advance

    Option Explicit

    Sub InsertImage_Click()
      Dim sPath As String, s As String, r As Range
      Dim Shp As Shape
      Dim PicRange As Range
      Dim c As Range, cell As Range, sname As String
      Dim diffwidth As Double, diffHeight As Double
      sPath = "D:\Images"
      If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
      Set r = Range("A2", Cells(Rows.Count, "A").End(xlUp))
      For Each cell In r
        cell.Offset(0, 1).Select
        Set c = cell.Offset(0, 1)
        s = sPath & cell.Value & ".jpg" 'remove the .jpg if the cell contains the extension
        sname = Dir(s)
        If sname <> "" Then
        Set PicRange = cell
        Set Shp = ActiveSheet.Shapes.AddPicture(Filename:=s _
            , LinkToFile:=False, SaveWithDocument:=True, Left:=PicRange.Left, Top:=PicRange.Top _
            , Width:=PicRange.Width, Height:=PicRange.Height)
          Shp.ScaleHeight Factor:=0.5, RelativeToOriginalSize:=msoTrue
          Shp.Height = 100
          If Shp.Height > 450 Then
            cell.EntireRow.RowHeight = 450
          Else
            cell.EntireRow.RowHeight = Shp.Height
          End If
          Shp.Left = c.Left
          Shp.Top = c.Top
        End If
      Next
    End Sub
    Last edited by pgujju143; 03-25-2016 at 05:31 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] list of subfolders in folder - without files and sub-subfolders
    By MartyZ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-11-2022, 10:56 AM
  2. Insert Picture to excel from subfolders and properly center in cell
    By munjajit in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-30-2015, 03:55 AM
  3. Create folders in all the subfolders and move subfolders
    By Amarjeet Singh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2015, 12:51 PM
  4. Easy way to insert images onto form
    By johncassell in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-02-2015, 06:39 AM
  5. Insert Multiple Hyperlinks from Folder and Subfolders
    By leonardapple in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 0
    Last Post: 02-27-2013, 11:10 AM
  6. [SOLVED] Insert Picture to excel from subfolders and save as folder name
    By gincemathew in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 02-14-2013, 10:01 AM
  7. Form Images
    By tekman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-17-2007, 08:21 AM

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