#1   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 25
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to microsoft.public.excel.programming
KL KL is offline
external usenet poster
 
Posts: 201
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA:: determine if UDF exists? George[_3_] Excel Discussion (Misc queries) 1 May 7th 07 12:57 PM
count how often a name exists hans[_3_] Excel Programming 5 January 28th 05 11:33 AM
How can I know if a sheet exists ? Ben.C Excel Programming 3 December 29th 03 09:36 AM
Worksheet Exists... James Weaver Excel Programming 3 October 6th 03 02:56 PM
How can I tell if a worksheet exists? Robert Stober Excel Programming 5 October 3rd 03 01:00 AM


All times are GMT +1. The time now is 01:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"