Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Exists?
How can I in Excel VBA check if folder exists?
Something like: path=C:\temp If path exists then a=true and same things for sheet sheetname=test1 if sheetname exists then a=true thanks tom |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Exists?
'----------------------------------------------------------------- Function FolderExists(Folder) As Boolean '----------------------------------------------------------------- Dim sFolder As String On Error Resume Next sFolder = Dir(Folder, vbDirectory) If sFolder < "" Then If (GetAttr(sFolder) And vbDirectory) = vbDirectory Then FolderExists = True End If End If End Function '----------------------------------------------------------------- Function SheetExists(Sh As String, _ Optional wb As Workbook) As Boolean '----------------------------------------------------------------- Dim oWs As Worksheet If wb Is Nothing Then Set wb = ActiveWorkbook On Error Resume Next SheetExists = CBool(Not wb.Worksheets(Sh) Is Nothing) On Error GoTo 0 End Function -- HTH RP (remove nothere from the email address if mailing direct) "Tom" wrote in message ... How can I in Excel VBA check if folder exists? Something like: path=C:\temp If path exists then a=true and same things for sheet sheetname=test1 if sheetname exists then a=true thanks tom |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Exists?
Hi Tom,
for path: If Dir(path)<"" Then a=True For sheet: On Error Resume Next Set s=Activeworkbook.Sheets(sheetname) On Error GoTo 0 If Not s Is Nothing Then a=True Regards, KL "Tom" wrote in message ... How can I in Excel VBA check if folder exists? Something like: path=C:\temp If path exists then a=true and same things for sheet sheetname=test1 if sheetname exists then a=true thanks tom |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Exists?
Hi tom
One way Sub testing1() Dim Dirname As String Dim fs As Object Set fs = CreateObject("Scripting.FileSystemObject") Dirname = "C:\Data\" If Not fs.FolderExists(Dirname) Then MsgBox "Not Exist" Else MsgBox "Exist" End If End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Tom" wrote in message ... How can I in Excel VBA check if folder exists? Something like: path=C:\temp If path exists then a=true and same things for sheet sheetname=test1 if sheetname exists then a=true thanks tom |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
VBA:: determine if UDF exists? | Excel Discussion (Misc queries) | |||
count how often a name exists | Excel Programming | |||
How can I know if a sheet exists ? | Excel Programming | |||
Worksheet Exists... | Excel Programming | |||
How can I tell if a worksheet exists? | Excel Programming |