The following code opens the default application for a filename:
Public Function OpenDefaultApplication(filename As String)
Dim sh As Object
Set sh = CreateObject("Shell.Application")
sh.Open (filename)
Set sh = Nothing
End Function
However, removing the brackets from the line opening the file means the file is not opened:
sh.Open filename ' does not work!
However, if I remove the code from a function, the code works successfully without brackets.
Dim sh As Object
Set sh = CreateObject("Shell.Application")
sh.Open filename ' works if not inside a function
Set sh = Nothing
What is this subtle different and why do the brackets become necessary inside a function?