vba: Check for network connection

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
826
Office Version
  1. 365
Platform
  1. Windows
I am looking for some code to add to the beginning of the code below to check for a network connection before continuing.... Thanks

Sub Job_Send()

If MsgBox("By pressing Yes you confirm that all information entered is correct.", _
vbCritical + vbYesNo, "") = vbNo Then Exit Sub
ActiveSheet.Unprotect
Dim ButtonName As Variant
Dim ButtonNames As Variant


ButtonNames = Array("Button 4", "Button 5", "Button 6")

For Each ButtonName In ButtonNames
ActiveSheet.Buttons(ButtonName).Visible = False
Next ButtonName

Range("h24").Select
Selection.Interior.ColorIndex = 6
ActiveCell.FormulaR1C1 = "OPERATOR CHECKED"
With ActiveCell.Characters(Start:=1, Length:=14).Font
.name = "Arial"
.FontStyle = "Bold"
.Size = 18
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With

With Range("A4:e22").Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Range("g4:n22").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With

Range("p4:p22").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With

Range("r4:t22").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With

Range("H20").Select
ActiveWorkbook.Save
ActiveWindow.SmallScroll Down:=-6
Range("I4").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveWorkbook.Save
ActiveWorkbook.SaveAs Filename:="H:\Burney Table\CUTTING FORMS (Protected by QC)\" & _
Format(Now(), "mm-dd-yyyy hh-mm-ss") & " BURNEY 1 JOB FORM", FileFormat:=xlNormal _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
Range("I4").Select

ButtonNames = Array("Button 8")

For Each ButtonName In ButtonNames
ActiveSheet.Buttons(ButtonName).Visible = False
Next ButtonName
ActiveWorkbook.Save

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"H:\Burney Table\Cutting Forms PDF\" & Format(Now(), "mm-dd-yyyy hh-mm-ss") & " BURNEY 1 JOB.pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True

ActiveWorkbook.Save
ActiveSheet.Unprotect

With Range("$H$1:$K$1")
.Locked = False
.FormulaHidden = False
End With

ActiveSheet.Protect Password:="1288", DrawingObjects:=True, Contents:=True, Scenarios:=True

ActiveWorkbook.Save


Workbooks.Open ("H:\Burney Table\BURNEY 1\operators form\BURNEY 1.xls")
Windows("BURNEY 1.xls").Activate
ActiveWorkbook.Save

ThisWorkbook.Close SaveChanges = True

Application.Quit

End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Not sure what you mean but if you just want to check to see if "H" is present then maybe the following would work.

Gary

Code:
Public Sub Test()

If Dir("H:\") = "" Then

    MsgBox "Error: Drive, path or file not found"
    
Else
    
    MsgBox "OK: Drive, path or file found"

End If

End Sub
 
Upvote 0
Thanks again Gary, I probably didnt explain very clear. That looks like what I need, I have several computers that are wireless and before they use the macro i described above I wanted to make sure the connection was there.
 
Upvote 0
Gary, can the code be modified were if the H is present it will not show a message box? msg box only when path is not found. Thanks
 
Upvote 0
Maybe like this.

Code:
Public Sub Test()

If Dir("H:\") = "" Then '"H" drive not found, abort sub

    	MsgBox "Error: Drive, path or file not found"
	Exit Sub
    
End If

'The rest of your code here

End Sub
</pre>
 
Upvote 0

Forum statistics

Threads
1,215,845
Messages
6,127,259
Members
449,372
Latest member
charlottedv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top