I have created an application for users that requires the user be connected to the network. I wanted to do a check to see if they are connected, and if the user is not connected they would get a message box telling them that they need to be connected to the network, then the workbook would close.
Below is the code I have, but when a user is not connected they do not get my messagebox, instead they get the excel error message "excel run-time error '52': bad file name or number", and the debugger line that gets highlighted is in the function DirExists that checks the length of the directory of the file path: Len(Dir(strpath))
Option Explicit Function DirExists(strpath As String) As Boolean If Len(Dir(strpath)) = 0 Then 'this is where the debugger highlights DirExists = False Else DirExists = True End If End Function Private Sub Workbook_Open() Dim strpath As String Dim strfile, strfile2 As String strpath = "\\n530fs1\PCLFileShares\pcl_reposit\Pricing_Tools\PAT\" If Not DirExists(strpath) Then MsgBox (" You Don't appear to be connected to the network, this file only works when this connection is available.") Exit Sub ActiveWorkbook.Close Savechanges:=False End If end sub
Could anyone please help me figure this out? Thanks in advance[hr]*[/hr] Auto Merged Post;[dl]*[/dl]Anyone out there to help? Thanks