Consider this code:
Public Function HelloWorld() As String
On Error GoTo ErrorHandler
Application.Workbooks("test.xlsm").Worksheets("Sheet1").Activate
Application.Workbooks("test.xlsm").Worksheets("Sheet1").Range("A1").Value = "Hello World"
HelloWorld = "Success"
Exit Function
ErrorHandler:
HelloWorld = Err.Description
End Function
When I run this within the developer's IDE with F5/F8 it will put "Hello World" in cell A1 as desired. But when I run this in the spreadsheet with "=HelloWorld()" I get the error "Application-defined or object-defined error".
What am I missing? Thanks in advance!