Results 1 to 12 of 12

Insert Picture To Cell in Col A with pic name in Col B

Threaded View

  1. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,529

    Re: Conditional compilation arguments vba

    Use this bit of code to get the list of jpg files in the folder, then that part of the error would be eliminated.
    Sub GetJPG()
    
        Dim y As Long
    
        Columns(2).ClearContents
        Range("B1") = "JPG Files"
        Application.ScreenUpdating = False
        
        With Application.FileSearch
    
            .LookIn = "C:\Documents and Settings\valued customer\My Documents\My Pictures\"    'Change to your location
            .FileType = msoFileTypeAllFiles
    
            For y = 1 To .FoundFiles.Count
    
                Sheet1.Cells(y + 1, 2) = Mid$(.FoundFiles(y), InStrRev(.FoundFiles(y), "\") + 1)
    
            Next
    
        End With
    
        OnlyJPG
    
    End Sub
    Sub OnlyJPG()
    'Filters just jpg files
        Dim Rws As Long, Rng As Range
    
        Rws = Cells(Rows.Count, "B").End(xlUp).Row
        Set Rng = Range(Cells(2, 2), Cells(Rws, 2))
    
        Rng.AutoFilter Field:=1, Criteria1:="<>*.JPG*", Operator:=xlAnd
        Rng.SpecialCells(xlCellTypeVisible).EntireRow.Delete
    
    End Sub
    .JPG will still remain in the file name so that part of your original code would not be required.
    Attached Files Attached Files
    Last edited by davesexcel; 02-26-2011 at 08:32 AM.

Thread Information

Users Browsing this Thread

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

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