-1
Good afternoon.
I have a macro, which searches a spreadsheet for the name of the photo (e.g., IMG0102.JPG), searches a predefined folder for the related photo and inserts it into the cell that bears the name of the photo.
However, I need to update this spreadsheet every day with new photos, however every time I run the macro it duplicates all the photos I had already inserted. Therefore, I would need this macro to skip each cell with photo (not to duplicate the ones you already have) and proceed only to the cells without photos
The following is an example of the spreadsheet:
Follow the macro that looks for the cell with the name of the photo and looks in the folder:
Sub InserirFotos()
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
Behold this answer
– danieltakeshi
My dear, I’m a little busy here and I haven’t looked at the code, but as you said it was working, it would be easier for you to create a new column like Statues, and when recording the image this column gets a value between 0 and 1. Where 0 has no photo and 1 has photo. When analyzing the code to record the photos check the status first and then insert the photo. Try it there, in case I can’t, I’ll take a look at the code.
– Braga
Good morning Kevin Valente, I created the code for you, I hope for sure. Obs.: I tried to put the code here, but I had some problems with the code, so I prefer to insert the download link. CREATING AND UPDATING LIST OF IMAGES FROM WINDOWS FOLDER. FILE DOWNLOAD LINK: https://drive.google.com/open?id=1poR5-FSLko3-AcHKrHxQKAG9u9BYg5Bm
– Braga
You should always put the code directly in your answer, because if that link breaks, in the future your answer will no longer be useful.
– Pedro Gaspar
I tried to put it, but Stackoverflow’s own page confuses what is code with comments, mixes lines of code and removes lines of code and becomes a writing on the page. That’s why I posted the link. But, if you can solve this problem or show me how to fix the code here.
– Braga
After entering the code in your text you can select all the lines of code and click the button
{ }
(Code sample), or you can also manually add 4 spaces at the beginning of each line of code, so the editor will already know that the snippet is code, and will do the proper formatting. Or, if you can’t, put wrong anyway, then someone edits your message to tidy up the formatting.– Pedro Gaspar
Please read how to edit code and edit your reply
– danieltakeshi