Macro for multiple worksheets

A

Amber

Any help would be appreciated. I have a workbook with several
spreadsheets that contain small picture files. Each time I open the
workbook I would like a macro to run on each worksheet and resize the
files to a specific size. The code I have so far is below. It only
resizes the images on the worksheet that is active when opening the
document. What am I missing?

Thanks!
---------------------------------------------

Sub Auto_Open()

Dim ws As Worksheet

For Each ws In Worksheets
ActiveSheet.DrawingObjects.Select
With Selection
.ShapeRange.LockAspectRatio = msoTrue
.ShapeRange.Height = 21#
.ShapeRange.Width = 24.75
.ShapeRange.Rotation = 0#
.Placement = xlMove
.PrintObject = True
End With
Next ws

End Sub
 
G

Gary Keramidas

untested, but have you tried this

ws.DrawingObjects.Select
instead of
ActiveSheet.DrawingObjects.Select
 
G

Gary Keramidas

no, didn't test the actual code. becasue i thought you mentioned it worked

this did work for me


Option Explicit
Sub r()
Dim ws As Worksheet

For Each ws In Worksheets

With ws.DrawingObjects
.ShapeRange.LockAspectRatio = msoTrue
.ShapeRange.Height = 21#
.ShapeRange.Width = 24.75
.ShapeRange.Rotation = 0#
.Placement = xlMove
.PrintObject = True
End With
Next ws

End Sub
 
A

Amber

Yes, but I get a runtime error on line .ShapeRange.LockAspectRatio =
msoTrue
Any other ideas?
Thanks!
Amber
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top