Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao dodo47,
la seguente routine l'ho testata con Excel 2003, 2013 e 2016. Forse va anche con Excel 2010.
Option Explicit
Public Sub aTest()
On Error GoTo ErrH
' --- PERSONALIZZARE ---------- >
'
Const cstrWshName As String = "Foglio1"
Const cstrPath As String = "D:\Percorso"
Const cstrExt As String = "jpg"
'
' --- PERSONALIZZARE ---------- <
Const clngBlock As Long = 1000
Dim app As Excel.Application
Dim wfn As Excel.WorksheetFunction
Dim wbk As Excel.Workbook
Dim wsh As Excel.Worksheet
Dim shps As Excel.Shapes
Dim rng As Excel.Range
Dim ps As String
Dim strPath As String
Dim strFile As String
Dim lngCount As Long
Dim astrFiles() As String
Dim i As Long
Dim r As Long
Set app = GetObject(Class:="Excel.Application")
With app
.ScreenUpdating = False
ps = .PathSeparator
Set wfn = .WorksheetFunction
Set wbk = .ThisWorkbook
End With
Set wsh = wbk.Worksheets(cstrWshName)
Set shps = wsh.Shapes
strPath = cstrPath
If Right$(strPath, 1) <> ps Then
strPath = strPath & ps
End If
ReDim astrFiles(0 To 0)
strFile = Dir(strPath & "*." & cstrExt, vbNormal)
Do While LenB(strFile)
lngCount = lngCount + 1
If lngCount > UBound(astrFiles) Then
ReDim Preserve astrFiles(LBound(astrFiles) _
To _
(1 + (UBound(astrFiles) \ clngBlock)) _
* clngBlock)
End If
astrFiles(lngCount - 1) = strPath & strFile
strFile = Dir
Loop
If lngCount Then
ReDim Preserve astrFiles(LBound(astrFiles) To lngCount - 1)
Else
MsgBox "Nessun file trovato."
GoTo ExtP
End If
' Test contenuto di astrFiles
'
'With wsh
' .Cells.Clear
' .Range("A1").Resize(lngCount, 1) = wfn.Transpose(astrFiles)
'End With
'GoTo ExtP
With wsh
.Cells.Clear
.DrawingObjects.Delete
End With
For i = LBound(astrFiles) To UBound(astrFiles)
r = 1 + 2 * i
Set rng = wsh.Cells(r, 1)
With rng
.RowHeight = 90
.ColumnWidth = 24
shps.AddPicture Filename:=astrFiles(i), _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=.Left, _
Top:=.Top, _
Width:=.Width, _
Height:=.Height
End With
Next
ExtP: On Error Resume Next
Excel.Application.ScreenUpdating = True
Set shps = Nothing
Set rng = Nothing
Set wsh = Nothing
Set wbk = Nothing
Set wfn = Nothing
Set app = Nothing
On Error GoTo 0
Exit Sub
ErrH: MsgBox Err.Description
Resume ExtP
End Sub