+ Reply to Thread
Results 1 to 2 of 2

import picture in specific cell if filename = cellnumber

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    import picture in specific cell if filename = cellnumber

    Hello!

    i am using this code to import pictures into my worksheet. After they are imported, the pictures are cropped and then placed in cell B3 and downward (B3, B4, B5, etc.)
    Sub InsertAllPictures()
    
        Dim strPath As String
        Dim strFileName As String
        Dim shpTemp As Shape
        Dim rngOutput As Range
        Dim Alert As String
        
           
            Rows("3:50").Select
            Selection.RowHeight = 140             ' Set row height to 150px
                
            Columns("B:B").Select
            Selection.ColumnWidth = 20            ' Set column width to 20px
                
            Range("B3").Select
                    
                    
            strPath = GetFolderName("Select a folder")
            strFileName = Dir(strPath & "\" & "*.bmp")
        
                    Alert = MsgBox("You selected this folder:" & strPath & "\" & strFileName, 0, "Your Selection")
                
                    Set rngOutput = ActiveSheet.Range("B3")
                        Do While Len(strFileName) > 0
                            ActiveSheet.Pictures.Insert strPath + "\" + strFileName
                            Set shpTemp = ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
                            With shpTemp
                                With .PictureFormat
                                    .CropLeft = 269
                                    .CropTop = 142
                                    .CropBottom = 309
                                    .CropRight = 402
                                End With
                                .Left = rngOutput.Left
                                .Top = rngOutput.Top
                            End With
                            Set rngOutput = rngOutput.Offset(1, 0)
                            strFileName = Dir
                        Loop
                    
                    
    
    End Sub
    However, the code is running perfectly fine, but the whole process which this macro is implemented is too complicated. Now, I would like to know if someone could help me please to arrange that the macro to do the following:
    1. impot the pictures (already done by macro)
    2. crop the pictures (already done by macro)
    3. I have a key number starting from A3 downwards (1, 2, 3, etc) and if the FILENAME of the picture (1.bmp, 2.bmp, 3.bmp) is the same as this key number, insert the picture in column B of that row.

    Hope someone understands what I mean!
    Thanks a lot!!!!!
    A2k

  2. #2
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    Re: import picture in specific cell if filename = cellnumber

    no idea...?

    basically this is a matter of comparing value in A3 (and onwards) and the filename. If the same, import, if not, do not.

    Any clues anyone?
    thanks!
    A2k

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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