Hi there, wonder if anyone can help me. I'm a bit of a macro amateur....
I have thousands of images that I wish to resize to 210mm wide.
I'm trying this but it's not working:
-Run Temporary Macro
-CTRL A
-CTRL G
-Then I type 210 into the 'width' box
- P (just to centralise it on the page)
-CTRL S
- Close page
- Stop recording
Then I load the images and press CTRL + SHIFT + P to run the temporary macro, it runs, closes the image down but when I go back and check it, it hasn't re-sized it!
Can anyone let me know please what I am doing wrong?
Thanks,
Mark
Hat-Trick Designs said:Thanks for this. Reason I just go for temporary macro is because this code means nothing to me unfortunately! Yeah, so I copied what you've shown above and it just re-sizes it to 210mm but doesn't maintain aspect ratio. And doesn't centre it on the page. How come when I record the macro, I change the width and I have the ratio 'locked', it doesn't reflect that in the macro? Surely if I wanted the picture distorted/stretched, I'd leave it unlocked?! When I'm recording the macro, what do I need to do differently to make it do what I want?
I really, really don't know the ins and outs of recording macros.
I do know a little bit about writing simple VBA macros, however - enough to easily write something that will do what you wanted your recorded macro to do.
The reason I was asking questions about your files is that, depending on how you have things organized, it might be easy to automate it even further, so that a macro could go after all of the documents in a folder automatically (open document, select all, resize proportionately, reposition to center of page, save document, close document).
Here is code that should do what I think you wanted to do using the macro recorder - on a single file, that is already open:
Sub Hat_Trick_01()Dim sr As ShapeRangeDim dblOrigWidth As DoubleDim dblOrigHeight As DoubleDim dblScaleFactor As DoubleConst dblTargetWidth As Double = 8.2677165 'target width, in inches 'set selection range Set sr = ActivePage.Shapes.All 'get width and size of selection range sr.GetSize dblOrigWidth, dblOrigHeight 'calculate scale factor to make the selection match the target width dblScaleFactor = dblTargetWidth / dblOrigWidth 'set the new size of the selection range sr.SetSize dblTargetWidth, dblOrigHeight * dblScaleFactor 'align selection range to page sr.AlignRangeToPage cdrAlignHCenter sr.AlignRangeToPage cdrAlignVCenter ActiveDocument.Save ActiveDocument.Close End Sub