Just add a Module to your project.
Change your Startup Object to "Sub Main" in Project Properties>Application Tab
Then add a Sub Main your module:
Module Module1
Sub Main()
'call your program code here instead of from your button click
End Sub
End Module
And yes you need to log your errors to a file instead of showing them in a Message Box