Sub InsImg()
Application.ScreenUpdating = False
ActiveSheet.Shapes.SelectAll
Selection.Delete
Dim Height As Single
Dim Width As Single
Dim Nfile As String
Dim Nfile1 As String
Dim Nfile2 As String
Dim Nfile3 As String
Dim Mfoto As String
Dim Mfoto1 As String
Dim Mfoto2 As String
Dim Mfoto3 As String
Dim mPath As String
mPath = "E:immagini_web"
R = 2 ''riga dalla quale iniziare la ricerca
LR = Range("A" & Rows.Count).End(xlUp).Row
For I = R To LR
Mfoto = ""
Mfoto2 = ""
Mfoto3 = ""
Nfile = ""
Nfile2 = ""
Nfile3 = ""
Mfoto = Replace(Cells(I, 1), "/", "_") '' INSERIRE IL NUMERO DELLA CELLA CHE CONTIENE IL CODICE
Mfoto2 = Replace(Cells(I, 3), "/", "_") '' INSERIRE IL NUMERO DELLA CELLA CHE CONTIENE IL CODICE
Mfoto3 = Left(Replace(Cells(I, 2), "/", "_"), 13) '' INSERIRE IL NUMERO DELLA CELLA CHE CONTIENE DESCRIZIONE
Nfile = Dir(mPath & "" & "*" & Mfoto & "*" & ".jpg")
Nfile2 = Dir(mPath & "" & "*" & Mfoto2 & "*" & ".jpg")
Nfile3 = Dir(mPath & "" & "*" & Mfoto3 & "*" & ".jpg")
''If Nfile = "" Then Nfile = Nfile2
''If Len(Mfoto) > 0 Then
If Nfile = "" And Nfile2 = "" And Nfile3 = "" Then Mfoto = "mancante"
If Nfile = "" And Nfile2 = "" And Nfile3 = "" Then Nfile = "mancante.jpg"
If Nfile = "" And Nfile2 <> "" Then Nfile = Nfile2 And Mfoto = Mfoto2
If Nfile = "" And Nfile2 = "" And Nfile3 <> "" Then Nfile = Nfile3 And Mfoto = Mfoto3
If Dir(mPath & "" & Nfile) <> "" Then '
''With ActiveSheet.Pictures.Insert(mPath & "" & mFoto & ".jpg")
'' SELEZIONARE LA CELLA DI DESTINAZIONE
With ActiveSheet.Shapes.AddPicture((mPath & "" & Nfile), False, True, 100, 50, -1, -1)
''ActiveSheet.Pictures.Insert (mPath & "" & Nfile)
Height = .Height
Width = .Width
.Top = Range("T" & I).Top
.Left = Range("T" & I).Left
.Height = Range("T" & I).Height
.Width = Width / (Height / Range("T" & I).Height)
''.Width = Range("O" & I).Width
Width = .Width
''For Each sh In ActiveWorkbook.Sheets
If Nfile = "mancante.jpg" Then Cells(I, 1).Interior.ColorIndex = 36
''Next
End With
End If
''End If
Next I
Application.ScreenUpdating = True
End Sub |