Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Test if a folder exists, create if it doesn't?

I'm sure this is simple, but after going through the Excel help file, all it
has done is confuse me. ;) Basically, I just want to see if a folder
exists, if it does, change to the folder, if it doesn't, create it, then
change to there.

I'll be getting user inputs that will be concatenated to come up with the
folder name I'm looking for/changing to. As well, I'll use that same info
to name some files that will be saved into that folder.

Thanks!!
Shawn
PS - sorry for a double post, had to set my date back to run an update, and
forgot to change it to the correct day before I posted this before.



--
Join the newest in Fantasy Sports.

http://www.6FantasySports.com
(this site supports the Victory Junction Gang Camp with a portion of all
proceeds)


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Test if a folder exists, create if it doesn't?

Hi

Try this:

Sub GoThere()
Dim NewFolder As String
NewFolder = "C:\Temp\NewOne"

On Error Resume Next
MkDir NewFolder
ChDrive NewFolder
ChDir NewFolder
'demo:
Application.Dialogs(xlDialogOpen).Show
End Sub


--
HTH. Best wishes Harald
Followup to newsgroup only please

"43fan" skrev i melding
...
I'm sure this is simple, but after going through the Excel help file, all

it
has done is confuse me. ;) Basically, I just want to see if a folder
exists, if it does, change to the folder, if it doesn't, create it, then
change to there.

I'll be getting user inputs that will be concatenated to come up with the
folder name I'm looking for/changing to. As well, I'll use that same info
to name some files that will be saved into that folder.

Thanks!!
Shawn
PS - sorry for a double post, had to set my date back to run an update,

and
forgot to change it to the correct day before I posted this before.



--
Join the newest in Fantasy Sports.

http://www.6FantasySports.com
(this site supports the Victory Junction Gang Camp with a portion of all
proceeds)




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 253
Default Test if a folder exists, create if it doesn't?

Hi

Use the Dir function
sub test
dim strMyFolder as string
strMyFolder = ""
strMyFolder = Dir("C:\MyfolderToCheck\")
if strMyFolder ="" then
msgbox "Folder does not exist
end if
end sub
Other solution, use the FileSystemObject.

Regards,
JY

"43fan" wrote in message
...
I'm sure this is simple, but after going through the Excel help file, all

it
has done is confuse me. ;) Basically, I just want to see if a folder
exists, if it does, change to the folder, if it doesn't, create it, then
change to there.

I'll be getting user inputs that will be concatenated to come up with the
folder name I'm looking for/changing to. As well, I'll use that same info
to name some files that will be saved into that folder.

Thanks!!
Shawn
PS - sorry for a double post, had to set my date back to run an update,

and
forgot to change it to the correct day before I posted this before.



--
Join the newest in Fantasy Sports.

http://www.6FantasySports.com
(this site supports the Victory Junction Gang Camp with a portion of all
proceeds)




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Test if a folder exists, create if it doesn't?

This is one way

Dim FSO As Object
Dim oFolder As Object
Dim sFolder As String

sFolder = "C:\MyTest\abc"

Set FSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set oFolder = FSO.getfolder(sFolder)
On Error GoTo 0
If oFolder Is Nothing Then
MkDir sFolder
End If

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"43fan" wrote in message
...
I'm sure this is simple, but after going through the Excel help file, all

it
has done is confuse me. ;) Basically, I just want to see if a folder
exists, if it does, change to the folder, if it doesn't, create it, then
change to there.

I'll be getting user inputs that will be concatenated to come up with the
folder name I'm looking for/changing to. As well, I'll use that same info
to name some files that will be saved into that folder.

Thanks!!
Shawn
PS - sorry for a double post, had to set my date back to run an update,

and
forgot to change it to the correct day before I posted this before.



--
Join the newest in Fantasy Sports.

http://www.6FantasySports.com
(this site supports the Victory Junction Gang Camp with a portion of all
proceeds)




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
Test if file exists Daniel Bonallack Excel Discussion (Misc queries) 2 May 4th 09 04:19 PM
How to check if a file exists in an ftp folder LL Cool A Excel Discussion (Misc queries) 3 May 16th 06 09:22 PM
Test if folder exists, create if it doesn't? 43fan Excel Programming 1 March 1st 04 04:31 PM
Test if a folder exists Jeff Marshall Excel Programming 6 September 30th 03 05:21 PM
Checking to see if Folder exists Dan[_25_] Excel Programming 2 September 24th 03 02:42 AM


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

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

About Us

"It's about Microsoft Excel"