Hello, brad2157
Welcome to the Board !!!!!
this is not exactly how you asked it, but let's see if it's OK for you ...
1. paste the code in a "normal" macro-module
2. assign the same macro to all your pictures using the code "assign_macro_to_all_pics"
3. whenever you click a picture it will enlarge
4a. clicking again the same picture, it will resize back to it's original state
4b. clicking another picutre will perform 4a and enlarge the one you just clicked
I assume this is userfriendly
Code:
Public PW As Integer 'picture width
Public PH As Integer 'picture height
Public PIC As Object
Dim RF As Single 'resize factor
Public LAR As Boolean
Public CloseFlag As Boolean
Sub zoom_pics()
'Erik Van Geit
'051124
'click a pick to enlarge
If Not PIC Is Nothing Then
If RF <> 0 Then
With PIC
.Width = PW
.Height = PH
.LockAspectRatio = LAR
End With
RF = 0
If CloseFlag Then Exit Sub
If ActiveSheet.Shapes(Application.Caller).Name = PIC.Name Then Exit Sub
Set PIC = Nothing
End If
End If
If CloseFlag Then Exit Sub
Set PIC = ActiveSheet.Shapes(Application.Caller)
Dim AW As Integer
Dim AH As Integer
With ActiveWindow.VisibleRange
AW = .Width
AH = .Height
End With
With PIC
LAR = .LockAspectRatio
.LockAspectRatio = msoTrue
PW = .Width
PH = .Height
RF = Application.Min(AW / PW, AH / PH) * 0.8
.Width = .Width * RF
End With
End Sub
Sub assign_macro_to_all_pics()
Const MacroName = "zoom_pics"
Const msg = "This procedure will assign the macro " & """" & MacroName & """" & _
" to all your pictures on this sheet." & vbLf & "Do you want to proceed?"
If MsgBox(msg, 292, "ASSIGN MACRO") = vbNo Then Exit Sub
On Error Resume Next
For Each PIC In ActiveSheet.Pictures
PIC.OnAction = MacroName
Next PIC
On Error GoTo 0
End Sub
Wait a moment ...
still one step to go
when the workbook is closed you need to restore the last picture if you forgot to do so
therefore paste this code into the workbookmodule
Code:
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
CloseFlag = True
zoom_pics
End Sub
it was a JOY to create this (although it could already exist somewhere...)
feel free to post comments
kind regards,
Erik
EDIT: just added one line three minutes after posting
If CloseFlag Then Exit Sub (second appearance)