Home |
Search |
Today's Posts |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
How to check drive exist ...
Ahhh! I'd like to change the name of that function. Function DriveExistsQ(sFilePath As String) As Boolean With CreateObject("Scripting.FileSystemObject") DriveExistsQ = .DriveExists(.GetDriveName(sFilePath)) End With End Function -- Dana DeLouis Windows XP & Office 2003 "Dana DeLouis" wrote in message ... How to check drive exist or not using FileSystemObject ? This idea uses the "DriveExists" method. Function FileExistsQ(sFilePath As String) As Boolean With CreateObject("Scripting.FileSystemObject") FileExistsQ = .DriveExists(.GetDriveName(sFilePath)) End With End Function Sub TestIt() Debug.Print FileExistsQ("C:\Windows") Debug.Print FileExistsQ("A:\Windows") Debug.Print FileExistsQ("D:\") End Sub Note the following when testing something like an A: Drive: 'A' might exist, but it is not "Ready" because it lacks a Disk. You may want to include an "IsReady" to make sure it has a Disk. -- HTH :) Dana DeLouis Windows XP & Office 2003 "moonhk" wrote in message ups.com... Dear Reader How to check drive exist or not using FileSystemObject ? Private Sub cmdSelectName_Click() Dim myFileName As Variant Dim FileObj As New FileSystemObject Dim loDriver As String Dim loFolder As String Dim loFilename As String On Error Resume Next loDriver = VBA.Trim(VBA.Left(txtfilename.Value, 2)) '~~ Check Drive exist of not '~~ Change Drive VBA.ChDrive (loDriver) loFilename = FileObj.GetFileName(txtfilename.Value) '~~ Return file name If VBA.InStr(1, txtfilename.Value, loFilename, vbTextCompare) 0 Then loFolder = VBA.Left(txtfilename, VBA.InStr(1, txtfilename.Value, loFilename, vbTextCompare) - 2) End If If FileObj.FolderExists(loFolder) Then VBA.ChDir (loFolder) End If On Error GoTo 0 myFileName = Application.GetOpenFilename(filefilter:="Prn Files, *.PRN", _ Title:="Pick a File") If myFileName = False Then '~~ MsgBox "Ok, try later" '~~user select cancel Exit Sub Else txtfilename.Value = myFileName End If End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Check for a tab if it is exist | Excel Discussion (Misc queries) | |||
How to check worksheets exist or not ? | Excel Programming | |||
Check if a value exist in a column | Excel Worksheet Functions | |||
Check if name exist in a list | Excel Programming | |||
Check if pivot already exist | Excel Programming |