Link to home
Create AccountLog in
Avatar of Andreas Hermle
Andreas HermleFlag for Germany

asked on

FResize graphics on currently active worksheet using VBA

Dear Experts:

for all the graphics on the currently active worksheet whose name start with "graphic_" should be formatted as follows:

Width and Height: 69%
Lock Aspect Ratio: checked
Relative To Original Picture Size: checked.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of Andreas Hermle

ASKER

Hi Rafael,

thank you very much for your swift help. I just noticed I cannot name graphics on the currently active sheet. I know how to do that for charts, but for graphics, I have got no idea.

Alternatively how would your coding change if I run this code on the selected graphics?
Uppps, Rafael I found out myself how to name the graphics (pressing Alt+F10 brings up the dialog box on which to work)

Anyway, how would your code change if I select the graphics and then run the macro?

Hi Fabrice: thank you very much for your help. Will test it and then let you know. I will get back to you tomorrow at the latest.

Thank you very much to both of you. Regards, Andreas
Avatar of Rgonzo1971
Rgonzo1971

if you want to use the selection

then try
Sub macro1()
For Each Shp In Selection
        Shp.ShapeRange.LockAspectRatio = msoTrue
        Shp.ShapeRange.ScaleHeight 0.69, msoTrue, msoScaleFromTopLeft
Next
End Sub

Open in new window

Hi Farbrice,

thank you very much for bringing your points to my attention. As a matter of fact, I am aware of all the things you said, especially that one should never use the 'Selection Object'.

Could you please tell me how to run your macro, if I run it a dialog box pops prompting me to select a macro.

Rafael, both codes work just fine. Thank you very much for :-)
Well, first you'll need to write a procedure without parameters so it will be callable as macro.
And within the procedure , call the procedure named macro with the right parameter.
Public Sub myProcedure()
    macro ThisWorkbook.Worksheets(1)
End Sub

Open in new window

Ok, Fabrice, thank you very much for your help. It works :-)

I suggest distributing the points 700 to 300 since Rafael was quicker to answer.
Thank you very much to both of you. Both codes work just fine. I really appreciate your professional expertise!