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

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,089
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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
before

xc8gXPA


after

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

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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