The function user_defined will always return False regardless of whether the variable loggedIn is True or False, unless the function declares a return value. So, this will give the appearance that the loggedIn public variable is not persisting as desired/expected. I suspect if you debug your code and step through it, you will observe that to be the case: loggedIn correctly is True, but the user_defined function is not returning the value correctly.
This apparently works for me
Public loggedIn As Boolean
Sub check_if_is_logged()
loggedIn = True
End Sub
Function user_defined()
Dim ret As Boolean
If loggedIn Then ret = True
user_defined = ret
End Function
In the loggedIn procedure I simply assume the user is logged in (of course you would have logic that determines whether True or False).
Then, if I query the user_defined function, by doing ?user_defined in the immediate window, the result is True.
The value of loggedIn does not revert back to False.
If you observe something different, then check your logic which could be mistaken, or perhaps you are doing something to End runtime which would clear out the public variables.
NOTE: This will not persist through an End statement (although it should persist through End Sub, End Function, End Type, End Enum, etc.). This will also not persist beyond closing the workbook/etc. You would need to save the value to a Name in the workbook, or to the CustomDocumentProperties collection.