+ Reply to Thread
Results 1 to 2 of 2

inserting images into the cell below it.

  1. #1
    Registered User
    Join Date
    02-21-2005
    Posts
    1

    inserting images into the cell below it.

    I have about 1000 images I need to insert into Excel. I would like to insert each image in a cell according to the row number. So the first image would be in A1, the next in B1, the next in C1, etc... Is there anyway to do this using macros? Doing it manually just takes forever. Any help would be appreciated.

  2. #2
    Registered User
    Join Date
    01-20-2004
    Location
    Western NY
    Posts
    99
    I am a little confused about cell location for these inserts. You stated

    "I would like to insert each image in a cell according to the row number. So the first image would be in A1, the next in B1, the next in C1, etc."

    Unless I misunderstand what you wish to do, the first image would be in A1, the 2nd in A2, the next in A3, etc. Ignoring that small point, I suggest you use the macro recorder to help you understand how to develop a macro to automate the insertion process. As an example, I turned on the macro recorder, manually hilited cell B18, manualy inserted an image, and then turned off the macro recorder. The resulting macro is:

    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 21-02-2005 by MWE
    '
    Range("B18").Select
    ActiveSheet.Pictures.Insert("D:\MiscImages\bigtree.jpg").Select

    End Sub

    So to automate the process for 1000 images, you need to:
    1. index from cell A1 to Cell A1000
    2. insert the relevant image into the cell

    The code to do this is pretty simple but you will learn more by creating it yourself.

    An outline of code might look something like this:

    Sub InsertImages()

    Dim I as Integer
    Dim FileName as String

    For I = 1 to 1000
    Cells(I,1).Select
    FileName = "D:\MiscImages\ABC" + ltrim(str(I)) + ".jpg"
    ActiveSheet.Pictures.Insert(FileName).Select
    Next I

    End Sub

    The code could be made more compact, but in the above form is fairly easy to understand. One important assumption is that you have stored and named the images in a way that the code can "figure out" what image belongs in, say, cell A241. In the above example, it is assumed that all images have some common alpha initially followed by asequential number. Thus the image that would be stored in A241 is ABC241.jpg

+ 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