Linking to a network drive

scorpweb

Board Regular
Joined
Jul 26, 2011
Messages
124
Hi all,

i have the below code and works fine on my PC

however i need to roll it out across a few PC's and dependant on the person to what Letter the "K" drive is (some people it's been mapped as T etc. as they have access to different drives to me or other people)

if there a way so i can link it to the network drive name?

Code:
Option Explicit
Public MyInteger As Integer
Public MyString As String
Public Sub DriveTest()
' Create a variable to hold the free space.
Dim FreeSpace As Double
' Create a reference to the file system.
Dim MyFileSystem As FileSystemObject
' Create a reference for the target drive.
Dim MyDrive As Drive
' Create a dialog result variable.
Dim Result As VbMsgBoxResult
'Provide a jump back point.
DoCheckAgain:
' Fill these two objects with data so they show the
' available space on drive C.
Set MyFileSystem = New FileSystemObject
Set MyDrive = MyFileSystem.GetDrive("K")
' Determine the amount of free space.
FreeSpace = MyDrive.AvailableSpace
' Make the check.
If FreeSpace < 1000000000 Then
' The drive doesn't have enough space. Ask what to
' do.
Result = MsgBox("The drive doesn't have enough " + _
"space to hold the data. Do you" + _
" want to correct the error?" + _
vbCrLf + _
Format(FreeSpace, "###,###") + _
" bytes available, " + _
"1,000,000,000 bytes needed.", _
vbYesNo Or vbExclamation, _
"Drive Space Error")
' Determine if the user wants to correct the error.
If Result = vbYes Then
' Wait for the user to fix the problem.
MsgBox "Please click OK when you have freed" + _
" some disk space.", _
vbInformation Or vbOKOnly, _
"Retry Drive Check"
' Go to the fallback point.
GoTo DoCheckAgain
Else
' The user doesn't want to fix the error.
MsgBox "The program can't save your data " + _
"until the drive has enough space.", _
vbInformation Or vbOKOnly, _
"Insufficient Drive Space"
' End the Sub.
Exit Sub
End If
Else
MsgBox "You've " & Format(FreeSpace, "###,###") + _
" bytes available, greater than the needed 1 GB" & vbCrLf & " Go on....", vbInformation, "Result..."
End If
End Sub



the network drive is "D_Customer003" on "filgpet03a02"

i think i'd probably have to have it as a seperate declaration but just can't get it to find the filepath :( can anyone help please!!!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,224,578
Messages
6,179,652
Members
452,934
Latest member
mm1t1

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