This might not be elegant, but- I'd try to query the SQL server, and if I get an error, telling me that I can't connect, then I'd assume (whether I was connected to the LAN or not) that I just can't connect to the SQL Server (it's a given). Knowing that, I'd go on to connecting to the local MSDE server.
As for replicating, sorry, can't help you there (yet).
I'm taking the System Administration for MS SQL Server 7.0 right now, and tomorrow (12/01) is the last day.
We'll be going over Replication, and I'll be sure to pay CLOSE attention (especially, since I'm planning on taking the exam before the end of the year, but also, for your benefeit too.) There IS a section on "Creating a Merge Publication", which I believe is your case. I'm just too tired tonight to read ahead. hehe. I'll try to get back to you sometime this weekend.
What version of SQL Server are you using BTW?