公式如下:
Sub InsertPictures()
'Update 20140513
Dim PicList() As Variant
Dim PicFormat As String
Dim Rng As Range
Dim sShape As Shape
On Error Resume Next
PicList = Application.GetOpenFilename(PicFormat, MultiSelect:=True)
xColIndex = Application.ActiveCell.Column
If IsArray(PicList) Then
xRowIndex = Application.ActiveCell.Row
For lLoop = LBound(PicList) To UBound(PicList)
Set Rng = Cells(xRowIndex, xColIndex)
Set sShape = ActiveSheet.Shapes.AddPicture(PicList(lLoop), msoFalse, msoCTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height)
xColIndex = xColIndex + 1
Next
End If
End Sub作者: samwang 時間: 2021-4-12 15:31
Sub InsertPictures()
'Update 20140513
Dim PicList() As Variant
Dim PicFormat As String
Dim Rng As Range
Dim sShape As Shape
On Error Resume Next
PicList = Application.GetOpenFilename(PicFormat, MultiSelect:=True)
xColIndex = Application.ActiveCell.Column
If IsArray(PicList) Then
xRowIndex = Application.ActiveCell.Row
For lLoop = LBound(PicList) To UBound(PicList)
If xColIndex > 5 Then xRowIndex = xRowIndex + 1: xColIndex = 1
Set Rng = Cells(xRowIndex, xColIndex)
Set sShape = ActiveSheet.Shapes.AddPicture(PicList(lLoop), msoFalse, msoCTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height)
xColIndex = xColIndex + 1
Next
End If
End Sub作者: Muffledsatyr 時間: 2021-4-15 06:52
Dim PicList() As Variant
Dim PicFormat As String
Dim Rng As Range
Dim sShape As Shape, n
On Error Resume Next
'ActiveSheet.Pictures.Delete '刪除全部圖片
PicList = Application.GetOpenFilename(PicFormat, MultiSelect:=True)
Set Rng = Application.ActiveCell
If IsArray(PicList) Then
For lLoop = LBound(PicList) To UBound(PicList)
Set sShape = ActiveSheet.Shapes.AddPicture(PicList(lLoop), msoFalse, msoCTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height)
n = n + 1
If n = 5 Then
n = 0
Set Rng = Rng.Offset(1, -4)
Else
Set Rng = Rng.Offset(0, 1)
End If
Next
End If
End Sub作者: ML089 時間: 2021-4-15 09:27
'貼滿5個後,換下一排在貼5個....以此類推
'注意! 執行程式前先選定貼圖執行位置
Sub InsertPictures_5()
Dim PicList() As Variant
Dim PicFormat As String
Dim Rng As Range
Dim sShape As Shape, n, Pages
On Error Resume Next
'ActiveSheet.Pictures.Delete '刪除全部圖片
PicList = Application.GetOpenFilename(PicFormat, MultiSelect:=True)
Set Rng = Application.ActiveCell
Pages = 5 '控制變數:貼滿5個後,換下一排在貼5個
If IsArray(PicList) Then
For lLoop = LBound(PicList) To UBound(PicList)
Set sShape = ActiveSheet.Shapes.AddPicture(PicList(lLoop), msoFalse, msoCTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height)
n = n + 1
If n = Pages Then '滿5格後
n = 0
Set Rng = Rng.Offset(1, 1 - Pages) '跳下一列,退回原起點
Else
Set Rng = Rng.Offset(0, 1)
End If
Next
End If
End Sub作者: samwang 時間: 2021-4-15 13:53
Sub tt()
Dim PicList, PicFormat$, Rng As Range, sShape As Shape, i&, X%, Y%
PicList = Application.GetOpenFilename(PicFormat, MultiSelect:=True)
X = 1 '從A1開始
If IsArray(PicList) Then
For i = 1 To UBound(PicList)
Y = Y + 1
If Y > 5 Then X = X + 1: Y = 1 '5張-->換下一列
Set Rng = Cells(X, Y) '貼上照片的位置
Set sShape = ActiveSheet.Shapes.AddPicture(PicList(i), msoFalse, msoCTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height)
Next
End If
End Sub作者: Muffledsatyr 時間: 2021-4-16 10:46
Sub tt2()
Dim PicList, PicFormat$, Rng As Range, sShape As Shape, i&, X%, Y%
PicList = Application.GetOpenFilename(PicFormat, MultiSelect:=True)
X = 1
If IsArray(PicList) Then
For i = 1 To UBound(PicList)
Y = Y + 1
If Y > 5 Then X = X + 1: Y = 1 '5張換下一列
Set Rng = Cells(X, Y)
Cells(X, Y).ColumnWidth = 42 '設定excel寬度
Cells(X, Y).RowHeight = 170 '設定excel高度
Set sShape = ActiveSheet.Shapes.AddPicture(PicList(i), msoFalse, msoCTrue, Rng.Left, Rng.Top, 7.72, 5.79) '數字可設定照片寬高
Next
End If
End Sub作者: Muffledsatyr 時間: 2021-4-17 10:20