Macro to automatically resize pasted images?

justjerry

New Member
Joined
Dec 12, 2011
Messages
3
I tried seeking help on ExcelForum.com but my post very quickly fell to the second page with no responses. Hopefully you all can help me out, it would greatly appreciated.

I am currently working on a project that requires me to screen capture web pages and then paste the images into a spread sheet, resized to 40% of their original size. Currently I have code in place that allows me to press Control E to resize a selected image. I would like to, instead, have the image automatically paste in at 40%. Either that or code that will paste, select, and then resize. I don't know how to select the pasted image and resize it using code though, as I'm not sure how to select the image once it's pasted.

Here is what I have so far, which works in that I have to select the pasted object and run the macro:

Sub resizeImages()

Selection.ShapeRange.ScaleWidth 0.63, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 0.63, msoFalse, msoScaleFromTopLeft

End Sub

THANKS!! ;)


<!-- BEGIN TEMPLATE: bbcode_quote -->
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
By no means do I know a lot of VBA but this is what I did.
I manually pasted some random pictures on Sheet 1

then created the following
Code:
Sub FortySize()
   Set myDocument = Worksheets(1)
   myDocument.Shapes.SelectAll
 
   Selection.ShapeRange.ScaleWidth 0.63, msoFalse, msoScaleFromTopLeft
   Selection.ShapeRange.ScaleHeight 0.63, msoFalse, msoScaleFromTopLeft
End Sub
and stepped through it with F8 and it resized all the images in 1 go.

See also http://msdn.microsoft.com/en-us/library/aa174305(v=office.11).aspx
 
Upvote 0
Re: Macro to automatically resize pasted images? SOLVED!

By no means do I know a lot of VBA but this is what I did.
I manually pasted some random pictures on Sheet 1

then created the following
Code:
Sub FortySize()
   Set myDocument = Worksheets(1)
   myDocument.Shapes.SelectAll
 
   Selection.ShapeRange.ScaleWidth 0.63, msoFalse, msoScaleFromTopLeft
   Selection.ShapeRange.ScaleHeight 0.63, msoFalse, msoScaleFromTopLeft
End Sub
and stepped through it with F8 and it resized all the images in 1 go.

See also http://msdn.microsoft.com/en-us/library/aa174305(v=office.11).aspx

Thank you for the help, that worked to an extent. I wanted something that would allow me to run the operation every time I pasted the image instead of at the end. I did find an answer online though, this is what I've come up with that works perfectly ... Control E pastes and resizes! :

Sub resizeImages()

'Selection.ShapeRange.ScaleWidth 0.63, msoFalse, msoScaleFromTopLeft
'Selection.ShapeRange.ScaleHeight 0.63, msoFalse, msoScaleFromTopLeft
ActiveSheet.Paste
With Selection
.Width = 350
.Height = 350
End With
End Sub

Thanks for your help!
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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