Inserting image files from a directory specified by text string

Closed
MattRNR Posts 8 Registration date Sunday April 3, 2016 Status Member Last seen April 18, 2016 - Apr 3, 2016 at 08:23 AM
MattRNR Posts 8 Registration date Sunday April 3, 2016 Status Member Last seen April 18, 2016 - Apr 18, 2016 at 07:46 AM
G’day CCM forum

Quick hypothetical; I have a list of image file names in a column on an excel spreadsheet and a cell at the top of the page containing a file directory name.

Is it possible to set up a macro that will automatically insert the corresponding image into the cell containing its file name from the specified file directory? Or into the cell adjacent?

Any thoughts on this or direction to relevant resources would be greatly appreciated

P.S. I’m quite a novice so my knowledge of lingo may be a little off

Regards

MattRNR

4 responses

G'Day Matt

With the Folder path in Cell A1 and the filename's of the pictures in cells A2, A3 etc. this will insert each picture into the adjacent cell B2, B3 etc.

Before to size column B and the rows for each picture before running the macro otherwise scaling doesn't seem to work after the fact.

Sub insertpictures()
LR = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row

For myRow = 2 To LR
PicturePath = Range("A1").Value & "\" & Range("A" & myRow).Value

With ActiveSheet.Pictures.Insert(PicturePath)
    With .ShapeRange
        .LockAspectRatio = msoTrue
        .Width = Cells(myRow, 2).Width
        .Height = Cells(myRow, 2).Height
    End With
    
    .Left = ActiveSheet.Cells(myRow, 2).Left
    .Top = ActiveSheet.Cells(myRow, 2).Top
    .Placement = xlMoveAndSize
End With
Next myRow

End Sub
0
MattRNR Posts 8 Registration date Sunday April 3, 2016 Status Member Last seen April 18, 2016
Apr 6, 2016 at 05:42 AM
G’day RayH

Alas I can’t seem to get this to work, I have paste the code into the ‘this workbook’ excel object and then run the macro however I receive an error box with the number 400 in it.

I’m certain this would work if I had any idea what I was doing, have you any idea what exceptionally obvious thing I am doing wrong?

Could I perhaps amend my initial question slightly?

If I were, alternatively, to have the full ‘picture path’ name in one cell (say A1) as well as a destination cell (say B1) both specified in a code, could this code be used to paste the image corresponding to that path in that destination cell?

It may be worth mentioning I'm designing a system to make price tags and I want to use this code to take the barcode image from a file of barcode images and past it directly into the template on the sheet

Cheers for any advice you can provide

Regards
Matt
0