|
Option Explicit
Sub test()
Dim ar, Items As FileDialogSelectedItems, strPath$, dNum#, dNum1#, shp As Shape
strPath = ThisWorkbook.Path & "\"
With Application.FileDialog(1)
With .Filters
.Clear
.Add "Excel Files", "*.bmp;*.jpg;*.png"
End With
.AllowMultiSelect = False
.InitialFileName = strPath
If .Show Then Set Items = .SelectedItems Else Exit Sub
End With
For Each shp In ActiveSheet.Shapes
If shp.Type = 11 Then shp.Delete
Next
dNum = [A1].MergeArea.Width / [A1].MergeArea.Height
ar = GetPic(Items(1))
[A1].Select
ActiveSheet.Pictures.Insert(Items(1)).Select
With Selection
.ShapeRange.LockAspectRatio = msoTrue
.Placement = xlMoveAndSize
If dNum < ar(0) / ar(1) Then
.Width = ActiveCell.MergeArea.Width - 6
Else
.Height = ActiveCell.MergeArea.Height - 6
End If
.Left = ActiveCell.Left + 3
.Top = ActiveCell.MergeArea.Top + 3
End With
Beep
End Sub
Function GetPic(ByVal strFileName$) As Long()
Dim ar&(1)
Dim Img As Object
With CreateObject("WIA.ImageFile")
.LoadFile strFileName
ar(0) = .Height: ar(1) = .Width
End With
GetPic = ar
End Function
|
|