ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Checking if you have a network connection (https://www.excelbanter.com/excel-discussion-misc-queries/91457-checking-if-you-have-network-connection.html)

clayton

Checking if you have a network connection
 

Hello,

I am using the below code (found on this site) to do a "Quick Save" to
a folder on my server. As it is now if there is not connection to the
network it saves the file locally to my "My Documents". Strange...
Anyway, I would like to know how to make this code tell me if there is
no connection and if not to ask what I would like to do with the file
(where to save it to).


Code:
--------------------
Public this_year

Sub Save_File()
this_year = Format(Date, "yyyy")

If Range("lotcode") = "" Then
MsgBox "Please enter a lot code"

Else

Call FindFile("totalpath")

End If
End Sub

Function FindFile(ByRef strPath As String)
Dim strFile As String
strFile = Dir(strPath)
If Len(strFile) Then
On Error Resume Next
fname = Range("product").Text & "-" & Range("lotcode").Text & ".xls"
pathname = "\\mynetwork folder\sub folder\" ' Substitute your pathname here
totalpath = pathname & this_year & "\"

ActiveWorkbook.SaveAs Filename:=totalpath & fname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
Else
On Error Resume Next
fname = Range("product").Text & "-" & Range("lotcode").Text & ".xls"
pathname = "\\mynetwork folder\sub folder\" ' Substitute your pathname here
totalpath = pathname & this_year & "\"

MkDir totalpath
ActiveWorkbook.SaveAs Filename:=totalpath & fname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False


End If

End Function
--------------------


--
clayton
------------------------------------------------------------------------
clayton's Profile: http://www.excelforum.com/member.php...fo&userid=4563
View this thread: http://www.excelforum.com/showthread...hreadid=547123



All times are GMT +1. The time now is 08:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com