Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default check and create folder for saveas

how do you chech if a folder exists and create one on A: drive is it is not
there ?
Please help a newbie- Thanks :-}



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default check and create folder for saveas

Hi Sunil,

One way

Sub Test()
Dim sFolder As String

sFolder = "C:\Mytest\New Dir"
If Not FolderExists(sFolder) Then
MkDir sFolder
End If

End Sub

'-----------------------------------------------------------------
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


--

HTH

RP

"Sunil" wrote in message
...
how do you chech if a folder exists and create one on A: drive is it is

not
there ?
Please help a newbie- Thanks :-}





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default check and create folder for saveas

Another way is to just ignore the error if there's a folder already there.

on error resume next
mkdir "a:\myfolder"
on error goto 0

This assumes that you wouldn't have a filename that has that name.



Sunil wrote:

how do you chech if a folder exists and create one on A: drive is it is not
there ?
Please help a newbie- Thanks :-}


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default check and create folder for saveas

If c:\mytest didn't exist, then I get an error when I try to make:
c:\mytest\new dir in one statement.


Bob Phillips wrote:

Hi Sunil,

One way

Sub Test()
Dim sFolder As String

sFolder = "C:\Mytest\New Dir"
If Not FolderExists(sFolder) Then
MkDir sFolder
End If

End Sub

'-----------------------------------------------------------------
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

--

HTH

RP

"Sunil" wrote in message
...
how do you chech if a folder exists and create one on A: drive is it is

not
there ?
Please help a newbie- Thanks :-}




--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default check and create folder for saveas

Just another idea...

s = "C:\Demo"
With CreateObject("Scripting.FileSystemObject")
If Not .FolderExists(s) Then .CreateFolder (s)
End With

--
Dana DeLouis
Win XP & Office 2003


"Bob Phillips" wrote in message
...
Hi Sunil,

One way

Sub Test()
Dim sFolder As String

sFolder = "C:\Mytest\New Dir"
If Not FolderExists(sFolder) Then
MkDir sFolder
End If

End Sub

'-----------------------------------------------------------------
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


--

HTH

RP

"Sunil" wrote in message
...
how do you chech if a folder exists and create one on A: drive is it is

not
there ?
Please help a newbie- Thanks :-}







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
Disable/ignore compatibility check during SaveAs [email protected] Excel Worksheet Functions 2 December 17th 09 05:07 AM
Creating a folder on SaveAs leerem Excel Discussion (Misc queries) 6 December 8th 08 12:51 PM
SaveAS to a specific folder, with operator input of file name [email protected] Excel Discussion (Misc queries) 1 January 5th 06 03:19 PM
How to: check if folder exist, if not, create escorido[_2_] Excel Programming 2 July 9th 04 01:28 PM
Create Folder and Text File in folder Todd Huttentsine Excel Programming 2 April 29th 04 03:41 PM


All times are GMT +1. The time now is 02:35 PM.

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"