0

I am getting an error when I use Application.Caller in Excel VBA.

I have a piece of code attached to a button/shape that I want to use to print a timestamp in the cell next to the button.

I need to use this button over and over so don't want to reference actual ranges of where to put the timestamp, so I thought this code would work.

However, each time the macro gets to the 2nd line, i.e. the Application.Caller row, it gives me an error:

ERROR 91 : 'Object variable or With block variable not set'

I would greatly appreciate if someone could assist with why this is happening as I can't fix it.

Thank you

I have tried activesheet.buttons as well as activesheet.shapes but neither have worked.

Dim x As Object
Set x = ActiveSheet.Shapes(Application.CALLER)
With x.TopLeftCell
Range(Cells(x.Row, x.Column), Cells(x.Row, x.Column)).Offset(0, 1).Select
End With
Fifi
  • 467
  • 6
  • 17
JDT
  • 107
  • 3
  • 14
  • 2
    Works for me with a shape. Your With clause is wrong though as `x` is the shape not a range. – SJR Jul 31 '19 at 09:50
  • 3
    The contents of the `With` clause is rather pointless as it ultimately returns `x.TopLeftCell`, [making some mistakes](https://stackoverflow.com/q/17733541/11683) in the process. The entire thing should be replaced with `x.TopLeftCell.Offset(0,1)`. – GSerg Jul 31 '19 at 09:54
  • 1
    It might help for you to determine exactly what value `Application.Caller` is returning in your specific scenario. There's code in the Help topic you could use. Quite possibly, it's returning something that can't be assigned to an `Object`... – Cindy Meister Jul 31 '19 at 11:30

0 Answers0