Image resizes in the wrong direction vba

muhhaque

New Member
Joined
Jun 6, 2022
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
For a project I have to make label with images. When I add the images they should resize towards right and it does just that when I use test images. However, when I use the actual images it resizes them and pushes them left.
issue1.PNG
issue2.PNG
issue3.PNG
issue4.png

VBA Code:
'This function just puts the pictures by the labels
Function PrintImage(pic As Variant)
    Dim PicRng As Range
    Dim PicShape As Shape
    PicColIndex = Application.ActiveCell.Column
        PicRowIndex = Application.ActiveCell.Row
            Set PicRng = Cells(PicRowIndex, PicColIndex)
            Set PicShape = ActiveSheet.Shapes.AddPicture(pic, msoTrue, msoCTrue, PicRng.Left, PicRng.Top, PicRng.Width, PicRng.Height)
            With PicShape
                .LockAspectRatio = msoCFalse
                .Height = 297
                .Width = 297
            End With
            PicRowIndex = PicRowIndex + 10
End Function
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Maybe your default MsoScaleFrom is set to msoScaleFromBottomRight (see MsoScaleFrom enumeration (Office))

I should suggest that you re-set Top and Left after resizing the shape:
VBA Code:
            With PicShape
                .LockAspectRatio = msoCFalse
                .Height = 297
                .Width = 297
                .Top = PicRng.Top
                .Left = PicRng.Left
            End With
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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