muhammad susanto
Well-known Member
- Joined
- Jan 8, 2013
- Messages
- 2,102
- Office Version
- 365
- 2021
- Platform
- Windows
hi all..
i have macro code to insert picture..actually, this macro work properly in only jpg format..
how to modified this macro can work in both .jpg and .png format.
here this code
any help me out . thanks in advance..
.sst
i have macro code to insert picture..actually, this macro work properly in only jpg format..
how to modified this macro can work in both .jpg and .png format.
here this code
VBA Code:
Sub Button1_Click()
Dim pic As Picture, rng As Range
For Each pic In ActiveSheet.Pictures
Set rng = Range(pic.TopLeftCell.Address, pic.BottomRightCell.Address)
If Not Intersect(rng, Range("B6:F6")) Is Nothing Then
pic.Delete
End If
Next pic
End Sub
Sub Button2_Click()
On Error GoTo NOT_SHAPE
Dim PicWtoHRatio As Single
Dim CellWtoHRatio As Single
Dim cel As Range
Selection.Copy
Set cel = Application.InputBox("Click on destination tab and cell", "", , , , , , 8)
With cel
.Parent.Activate
.Activate
.Parent.Paste
End With
With Selection
PicWtoHRatio = .Width / .Height
End With
With cel
CellWtoHRatio = .Width / .RowHeight
End With
Select Case PicWtoHRatio / CellWtoHRatio
Case Is > 1
With Selection
.Width = cel.Width
.Height = .Width / PicWtoHRatio
End With
Case Else
With Selection
.Height = cel.RowHeight
.Width = .Height * PicWtoHRatio
End With
End Select
With Selection
.Top = cel.Top
.Left = cel.Left
End With
Exit Sub
NOT_SHAPE:
MsgBox "Select a picture before running this macro."
End Sub
any help me out . thanks in advance..
.sst