VBA : Change width Column or Height Picture [NOT FIT CELL]

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,102
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi all..

this macro code work properly for fit cell, i want to change column width height row in left margin and right margin [not fit cell]
Code:
[COLOR=Navy]Sub[/COLOR][COLOR=#333333] InsertPic()        [/COLOR]    [COLOR=Navy]Dim[/COLOR] I [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long[/COLOR]
    [COLOR=Navy]Dim[/COLOR] xPath [COLOR=Navy]As[/COLOR] [COLOR=Navy]String[/COLOR]
    [COLOR=Navy]Dim[/COLOR] xShape [COLOR=Navy]As[/COLOR] Shape
    [COLOR=Navy]Dim[/COLOR] a  [COLOR=Navy]As[/COLOR] Range
    
    xPath = "L:\test\"
    
    [COLOR=Navy]If[/COLOR] Dir(xPath & "*.jpg") = "" [COLOR=Navy]Then[/COLOR]
        MsgBox "Picture file was not found in path!", vbInformation, "test"
        [COLOR=Navy]Exit[/COLOR] [COLOR=Navy]Sub[/COLOR]
    [COLOR=Navy]End[/COLOR] If
    
    [COLOR=Navy]For[/COLOR] I = 1 To ActiveWorkbook.Sheets.Count
        [COLOR=Navy]Set[/COLOR] a = Sheets(I).Range("H10")
            a.RowHeight = 100
            a.ColumnWidth = 20
            [COLOR=Navy]Set[/COLOR] xShape = Sheets(I).Shapes.AddPicture(xPath & I & ".jpg", True, True, a.Left, a.Top, a.Width, a.Height)
    [COLOR=Navy]Next[/COLOR]
 [COLOR=Navy]End[/COLOR][COLOR=#333333] [/COLOR][COLOR=Navy]Sub[/COLOR]

i attachment with image to easy understand it

thanks in advance...

.sst
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
before

xc8gXPA


after

https://imgur.com/pXKfAVC
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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