|
Sub 插图片到批注保留原尺寸()
Dim cell As Range, fd, t
Selection.ClearComments
If Selection(1) = "" Then MsgBox "不能选择空白区。", 64, "提示": Exit Sub
On Error Resume Next
Set fd = Application.FileDialog(msoFileDialogFolderPicker) '允许用户选择一个文件夹
If fd.Show = -1 Then
t = fd.SelectedItems(1) '选择之后就记录这个文件夹名称
Else
Exit Sub '否则就退出程序
End If
For Each cell In Selection
err.Clear
ActiveSheet.Pictures.Insert(t & "\" & cell.Text & ".jpg").Select
If err.Number = 0 Then
fswith = Selection.Width
Fsheight = Selection.Height
Selection.Delete
With ActiveCell.AddComment
.Visible = True
.Text Text:=""
.Shape.Select True
Selection.ShapeRange.Fill.UserPicture t & "\" & cell.Text & ".jpg"
.Shape.Width = fswith 'Add these 2 statement
.Shape.Height = Fsheight
cell.Offset(1, 0).Select
.Visible = False
End With
Else
MsgBox "未找到同名的JPG图片!", 64, "提示"
End If
Next
End Sub |
|