VB Code to resize an image

ateebali

Board Regular
Joined
Dec 13, 2018
Messages
108


New
<article>
This code I am using but the issue is width of picture, it is not fixing in A34:C34 and stretching it all the way to Column P

Please please help

Sub GetPic()
Dim fNameAndPath As Variant
Dim img As Picture
fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
If fNameAndPath = False Then Exit Sub
Set img = ActiveSheet.Pictures.Insert(fNameAndPath)
With img
'Resize Picture to fit in the range....
.Left = ActiveSheet.Range("A34").Left
.Top = ActiveSheet.Range("A34").Top
.Width = ActiveSheet.Range("A34:C34").Width
.Height = ActiveSheet.Range("A34:A48").Height
.Placement = 1
.PrintObject = True
End With
End Sub​
</article>


 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
It worked for me when i switched the width with the height. Can you try that?

Code:
Sub GetPic()
Dim fNameAndPath As Variant
Dim img As Picture
fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
If fNameAndPath = False Then Exit Sub
Set img = ActiveSheet.Pictures.Insert(fNameAndPath)
With img
'Resize Picture to fit in the range....
.Left = ActiveSheet.Range("A34").Left
.Top = ActiveSheet.Range("A34").Top
.Height = ActiveSheet.Range("A34:A48").Height
.Width = ActiveSheet.Range("A34:C34").Width
.Placement = 1
.PrintObject = True
End With
End Sub
 
Upvote 0
Thanks dear, yes width issue now resolved but now height issue is there like now height is reduced with cell A34:C38
IT SHOULD BE A34:C48
 
Upvote 0

Forum statistics

Threads
1,214,382
Messages
6,119,194
Members
448,874
Latest member
Lancelots

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