Good afternoon.
I have a macro, which searches a worksheet for the name of the photo (eg IMG0102.JPG), searches the predefined folder for a related photo, and inserts it into the cell that is the name of the photo.
However, I need to update this worksheet every day with new photos, however every time I run the macro it duplicates all the photos I've already inserted. Therefore, you would need this macro to skip each cell with a photo (not to duplicate the ones it already has) and follow only the cells without photos
Here is an example of the spreadsheet:
Hereisthemacrothatlooksforthecellwiththenameofthephotoandsearchesthefolder:
SubInserirFotos()imgpasta="xxxxxxxxx\" ' caminho da pasta das fotos
For i = 2 To 1000 'Numero das Linhas ' inicio e fim para inserir fotos
For j = 28 To 35 'Numero das Colunas ' inicio e fim das colunas de onde estao os nomes das fotos
imgleft = ActiveSheet.Cells(i, j).Left
imgtop = ActiveSheet.Cells(i, j).Top
imgwidth = ActiveSheet.Cells(i, j).Width
imgheight = ActiveSheet.Cells(i, j).Height
imagem = Trim(ActiveSheet.Cells(i, j).Value)
If imagem <> "" Then
If Dir(imgpasta + imagem) <> "" Then
ActiveSheet.Shapes.AddPicture imgpasta + imagem, True, True, imgleft, imgtop, imgwidth, imgheight
End If
End If
Next j
Next i
ActiveSheet.Shapes.SelectAll
Selection.Placement = xlMoveAndSize
End Sub