Hi, I'm trying out a new module where I'm trying to code an image as a global variable. I'm new to VBA so please forgive me if I'm doing some things wrong:
However, when I try to reference this image in other subs, Excel doesn't recognise it. E.g. this example:
Could you help to let me know why the global variable isn't working as intended? Did I define some things wrongly etc. Your help is much appreciated!
VBA Code:
Public Sub Variables()
Global Astronaut As Shape
'Astronaut is the variable name (Image name)
Global ws As Worksheet
Set ws = ActiveSheet
Set Astronaut = ws.Shapes("New Image Name")
Astronaut.Name = "New Image Name"
End Sub
However, when I try to reference this image in other subs, Excel doesn't recognise it. E.g. this example:
Code:
Astronaut.Select
Selection.Cut
Range("R18").Select
ActiveSheet.Paste
Selection.TopLeftCell.Select
Could you help to let me know why the global variable isn't working as intended? Did I define some things wrongly etc. Your help is much appreciated!