ActiveSheet.Shapes.AddPicture - How to improve quality of images?

Rodolfo SN

New Member
Joined
Aug 16, 2018
Messages
1
Hi, guys.
I am using "ActiveSheet.Shapes.AddPicture" to import images into my worksheet, however the pictures decrease quality every time I did that.
Is there any way to set a better resolution or something that help this point?

Code:
Sub Insere()
BoolImage = True
Dim Imagem As Object
Dim ImgFileFormat As String
ImgFileFormat = "Image Files JPG (*.jpg),*.jpg, Image Files NEF (*.nef),*.nef, Image Files JPEG (*.jpeg),*.jpeg, Image Files GIF (*.gif),*.gif, Image Files BMP (*.bmp),*.bmp"
Pict = Application.GetOpenFilename(ImgFileFormat)
If Pict = False Then
'End
BoolImage = False
Else


Set Imagem = ActiveSheet.Shapes.AddPicture(Pict, False, True, 1, 1, -1, -1)
Imagem.Top = ActiveCell.Top
Imagem.Left = ActiveCell.Left

Imagem.Placement = xlMoveAndSize


Dim escala
Dim deslocamento
If Imagem.Height > 187 Then
escala = 187 / Imagem.Height
Imagem.Height = Imagem.Height * escala
'Imagem.Width = Imagem.Width * escala
Imagem.Select
deslocamento = (((385 - Imagem.Width) / 2))
Selection.ShapeRange.IncrementLeft deslocamento
deslocamento = (((187 - Imagem.Height) / 2)) ' O valor de 191 encontrado através da multiplicação da altura das células
Selection.ShapeRange.IncrementTop deslocamento
ElseIf Imagem.Width > 383 Then
escala = 370 / Imagem.Width
'Imagem.Height = Imagem.Height * escala
Imagem.Width = Imagem.Width * escala
Imagem.Select
deslocamento = (((191 - Imagem.Height) / 2))
Selection.ShapeRange.IncrementTop deslocamento
deslocamento = (((375 - Imagem.Width) / 2)) ' Valor de 385 encontrado experimentalmente / Excel tem unidades diferentes para Height e e Widht
Selection.ShapeRange.IncrementLeft deslocamento

End If
End If


End Sub
 
Last edited by a moderator:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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