Talaytalo
Thành viên mới
- Tham gia
- 21/4/20
- Bài viết
- 12
- Được thích
- -13
Sub InserPictureByName()
'Updateby Extendoffice
Dim xFDObject As FileDialog
Dim xStrPath, xStrPicPath As String
Dim xRgName, xRgInser, xRg, xRgI As Range
Dim xFNum As Integer
Set xFDObject = Application.FileDialog(msoFileDialogFolderPicker)
With xFDObject
.Title = "Please select the folder:"
.InitialFileName = Application.ActiveWorkbook.Path
.Show
.AllowMultiSelect = False
End With
On Error Resume Next
xStrPath = ""
xStrPath = xFDObject.SelectedItems.Item(1)
If xStrPath = "" Then
Exit Sub
End If
Set xRgName = Application.InputBox("Please select the cells contain the image name:", "Kutools for Excel", , , , , , 8)
If xRgName Is Nothing Then
MsgBox "No cells are select, exit operation! ", vbInformation, "Kutools for Excel"
Exit Sub
End If
Set xRgInser = Application.InputBox("Please select the cells to output the images", "Kutools for Excel", , , , , , 8)
If xRgInser Is Nothing Then
MsgBox " No cells are select, exit operation.! ", vbInformation, "Kutools for Excel"
Exit Sub
End If
For xFNum = 1 To xRgName.Count
Set xRg = xRgName.Item(xFNum)
Set xRgI = xRgInser.Item(xFNum)
xStrPicPath = xStrPath & "\" & xRg.Text & ".png" & ".jpg"
If Not Dir(xStrPicPath, vbDirectory) = vbNullString Then
With xRgI.Parent.Pictures.Insert(xStrPicPath)
.Left = xRgI.Left
.Top = xRgI.Top
.ShapeRange.LockAspectRatio = msoFalse
.ShapeRange.Height = 60
.ShapeRange.Width = 60
End With
End If
Next
End Sub
'Updateby Extendoffice
Dim xFDObject As FileDialog
Dim xStrPath, xStrPicPath As String
Dim xRgName, xRgInser, xRg, xRgI As Range
Dim xFNum As Integer
Set xFDObject = Application.FileDialog(msoFileDialogFolderPicker)
With xFDObject
.Title = "Please select the folder:"
.InitialFileName = Application.ActiveWorkbook.Path
.Show
.AllowMultiSelect = False
End With
On Error Resume Next
xStrPath = ""
xStrPath = xFDObject.SelectedItems.Item(1)
If xStrPath = "" Then
Exit Sub
End If
Set xRgName = Application.InputBox("Please select the cells contain the image name:", "Kutools for Excel", , , , , , 8)
If xRgName Is Nothing Then
MsgBox "No cells are select, exit operation! ", vbInformation, "Kutools for Excel"
Exit Sub
End If
Set xRgInser = Application.InputBox("Please select the cells to output the images", "Kutools for Excel", , , , , , 8)
If xRgInser Is Nothing Then
MsgBox " No cells are select, exit operation.! ", vbInformation, "Kutools for Excel"
Exit Sub
End If
For xFNum = 1 To xRgName.Count
Set xRg = xRgName.Item(xFNum)
Set xRgI = xRgInser.Item(xFNum)
xStrPicPath = xStrPath & "\" & xRg.Text & ".png" & ".jpg"
If Not Dir(xStrPicPath, vbDirectory) = vbNullString Then
With xRgI.Parent.Pictures.Insert(xStrPicPath)
.Left = xRgI.Left
.Top = xRgI.Top
.ShapeRange.LockAspectRatio = msoFalse
.ShapeRange.Height = 60
.ShapeRange.Width = 60
End With
End If
Next
End Sub