I'm using Microsoft Excel 2010 on Windows 7. I have an assignment that requires me to keep on embedding objects of a compressed file into a cell in a Microsoft Excel worksheet every few minutes.
The icon of the compressed file is large and takes up the height of three adjacent cells. So every time I embed the compressed file, I right click on the icon and then select the format object menu item, followed by changing the size of the icon to 50% of its original size.
Is there a way to set the default size of an icon in Microsoft Excel? If not is there a way to automate the procedure of setting the format of the embedded object using a macro? I searched a lot but could not find anything. I tried VBA script for one particular object but cannot do it for any object
Thank you for any inputs
Edit: thank you for the comment requiring me to post to the macro. Here is a macro that I had recorded but it is only for a specific object which is object 21. There are multiple problems with this code which I am outlining below the code
Sub Reduce_size_icon()
'
' Reduce_size_icon Macro
' Reduce the size of the icon
'
'
ActiveSheet.Shapes("Object 21").LockAspectRatio = msoTrue
ActiveSheet.Shapes("Object 21").Height = 20.25
ActiveSheet.Shapes("Object 21").Width = 69.75 End Sub
- This is only for a specific object. One way maybe to loop through all the possible objects on a worksheet and then reduce their height. But if I am adding the objects one by one, the macro needs to run only on the last object and not all of the ones prior to do it because they have already been formatted, especially if we want the height and width to be reduced by 50% of the current dimensions. (See point 2)
- it would be better if we can reduce the height by half instead of assigning absolute values to the height. This is because sometimes I may have objects of different files and therefore of different icon sizes.
- After going through your comment, I realized that maybe it is much easier to create a macro which will automatically embed and format an object into the highlighted cell on which the macro is run. However, what we want is that the object should be created from a different file every time. So is it possible that the macro can run through exactly the same steps of building an object but at the point where it prompts you for the file path, it can stop and allow the user to choose a particular file?
And of course, the easiest way is to be able to specify the size of the icon to default values so that it always embeds with a smaller size.