Cell Resizing with Images

kpraytor

New Member
Joined
Sep 8, 2011
Messages
6
Good Morning! Long time reader of the forums, first time posting.

I am having a hard time with resizing the cells in my worksheet based on the image size with VBA. Essentially what I am trying to do is resize the row height based on the height of the image. My problem is when I attempt to get some code from the macro recorder, I see nothing concerning the image height.

All the images are in column A, extending from rows 1 to 2725. Every image is a different size, but all images are contained in their respective cells (don't know how to attach an excel document in a post).

I would truly appreciate some help with this as I do not know how to use VBA to extract the needed image height or how to resize the row based on that image height.

Thanks in advance

PS: If someone could show me how to attach an excel spreadsheet, that might make this process much easier :)
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Example:

Code:
Sub Test()
    Dim Pic As Picture
    Dim h As Double
    Dim w As Double
    Set Pic = ActiveSheet.Pictures("Picture 1")
    With Pic
        h = .Height
        With .TopLeftCell
            .RowHeight = h
        End With
    End With
End Sub
 
Upvote 0
Thanks for the snippet of code.

Unfortunately I get Runtime Error '1004: Unable to get the Pictures property of the worksheet class.

Let me add some more information as I'm sure this error is due to my lack of:

The images are contained in "c:\Documents and Settings\praytokl\My Documents\Personal\Stamps\Scott_2007._Standard_Postage_Stamp_Catalogue.vol.1\vol. 1" if that helps at all.

Also, for the names of the images:
-XXX.jpg or -XXX.bmp for any number image under 1000 (eg "-056.jpg")
-XXXX.jpg or -XXXX.bmp for any number image over 1000 (eg "-2150.jpg")

The images are already pasted into the document, so I'm not sure the image location and file naming is of any help.

Please ask if there is any other pertinent information that is needed.
 
Last edited:
Upvote 0
Change "Picture 1" to the name of your picture. If you click it its name will appear in the Name box to the left of the Formula bar. Or you could loop around the Pictures collection.
 
Upvote 0
I could jump up and down that works so perfectly! All I have to do now is loop it for 2,725 times! :eeek:

Thanks again for the quick responses and simple solutions.

I will continue to stick around and help if I can!

:biggrin::biggrin::biggrin:
 
Upvote 0
I'm having some trouble changing the picture name within the loop (incrementing it to the next picture: Picture 1 => Picture 2)

Any ideas?
 
Upvote 0
As I said you can loop around the Pictures collection:

Code:
Sub Test()
    Dim Pic As Picture
    Dim h As Double
    For Each Pic In ActiveSheet.Pictures
        With Pic
            h = .Height
            With .TopLeftCell
                .RowHeight = h
            End With
        End With
    Next Pic
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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