Vba Insert Picture Not Work in. PNG format

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,077
Office Version
  1. 365
  2. 2021
Platform
  1. 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
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
 
Yet again you have ignored our rules & cross posted this without supplying links.
Please supply all relevant links.
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,223,268
Messages
6,171,099
Members
452,379
Latest member
IainTru

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top