Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Creating a Directory from a user input

Hi

This is working for me with in G4 "C:\Data" (The Data folder already exist)
and in I3 "Testfolder"

Sub MakeDirectory()
Dim project_dir As String
Dim Project_spec As String
Dim Project_path As String
Dim fs As Object

Set fs = CreateObject("Scripting.FileSystemObject")

project_dir = Worksheets("Road Editor").Range("G4")
Project_spec = Worksheets("Road Editor").Range("I3")
Project_path = project_dir & "\" & Project_spec

If Not fs.FolderExists(Project_path) Then
fs.CreateFolder Project_path
Else
' do nothing
End If
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"mathew" wrote in message ...
I need to check to see if a directory exists and if it does not then create it. I can do this when I specify the directory in the

last two lines of the VB sub-routine, however, I need to get the path statement from 2 different user input cells on the worksheet.
Here is what I have. Can you please help!

Dim project_dir As String
Dim Project_spec As String
Dim Project_path As String

project_dir = Worksheets("Road Editor").Range("G4")
Project_spec = Worksheets("Road Editor").Range("I3")
Project_path = project_dir & "\" & Project_spec
On Error Resume Next
ChDir "Project_path"
If Err < 0 Then MkDir "Project_path"



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Creating a Directory from a user input

Hi mathew

and in I3 "Testfolder"

I assume that you leave out the "" ""

Is it working with this line
Project_path = "C:\Data\Testfolder"



--
Regards Ron de Bruin
http://www.rondebruin.nl


"mathew" wrote in message ...
Ron: I can't get it to work. I can get my code to work when I type the path into my statements.
This line:
fs.CreateFolder Project_path
is in yellow.

The Project_path is correct, but the line does not execute. Do I have some setting wrong? I used your values in G4 C:\Data Like

yours the Data folder already exists
and in I3 "Testfolder"
Any suggestions would be welcom,ed! Thanks so much for your help!

"Ron de Bruin" wrote:

Hi

This is working for me with in G4 "C:\Data" (The Data folder already exist)
and in I3 "Testfolder"

Sub MakeDirectory()
Dim project_dir As String
Dim Project_spec As String
Dim Project_path As String
Dim fs As Object

Set fs = CreateObject("Scripting.FileSystemObject")

project_dir = Worksheets("Road Editor").Range("G4")
Project_spec = Worksheets("Road Editor").Range("I3")
Project_path = project_dir & "\" & Project_spec

If Not fs.FolderExists(Project_path) Then
fs.CreateFolder Project_path
Else
' do nothing
End If
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"mathew" wrote in message ...
I need to check to see if a directory exists and if it does not then create it. I can do this when I specify the directory in

the
last two lines of the VB sub-routine, however, I need to get the path statement from 2 different user input cells on the

worksheet.
Here is what I have. Can you please help!

Dim project_dir As String
Dim Project_spec As String
Dim Project_path As String

project_dir = Worksheets("Road Editor").Range("G4")
Project_spec = Worksheets("Road Editor").Range("I3")
Project_path = project_dir & "\" & Project_spec
On Error Resume Next
ChDir "Project_path"
If Err < 0 Then MkDir "Project_path"






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Creating a Directory from a user input

Ron: Thank you very much for the help!
I did leave off the " " on testfolder!
To answer your question: No the line does not works when I put in the sub routine. However, the code below works, but is not functional the way I need it to be! I need the user to input the path as the file name. This file will be used by many different users on different systems. Any help would be appreciated.

On Error Resume Next
ChDir "C:\Network_2000\Current_projects\Network files"
If Err < 0 Then MkDir "C:\Network_2000\Current_projects\Network files"

"Ron de Bruin" wrote:

Hi mathew

and in I3 "Testfolder"

I assume that you leave out the "" ""

Is it working with this line
Project_path = "C:\Data\Testfolder"



--
Regards Ron de Bruin
http://www.rondebruin.nl


"mathew" wrote in message ...
Ron: I can't get it to work. I can get my code to work when I type the path into my statements.
This line:
fs.CreateFolder Project_path
is in yellow.

The Project_path is correct, but the line does not execute. Do I have some setting wrong? I used your values in G4 C:\Data Like

yours the Data folder already exists
and in I3 "Testfolder"
Any suggestions would be welcom,ed! Thanks so much for your help!

"Ron de Bruin" wrote:

Hi

This is working for me with in G4 "C:\Data" (The Data folder already exist)
and in I3 "Testfolder"

Sub MakeDirectory()
Dim project_dir As String
Dim Project_spec As String
Dim Project_path As String
Dim fs As Object

Set fs = CreateObject("Scripting.FileSystemObject")

project_dir = Worksheets("Road Editor").Range("G4")
Project_spec = Worksheets("Road Editor").Range("I3")
Project_path = project_dir & "\" & Project_spec

If Not fs.FolderExists(Project_path) Then
fs.CreateFolder Project_path
Else
' do nothing
End If
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"mathew" wrote in message ...
I need to check to see if a directory exists and if it does not then create it. I can do this when I specify the directory in

the
last two lines of the VB sub-routine, however, I need to get the path statement from 2 different user input cells on the

worksheet.
Here is what I have. Can you please help!

Dim project_dir As String
Dim Project_spec As String
Dim Project_path As String

project_dir = Worksheets("Road Editor").Range("G4")
Project_spec = Worksheets("Road Editor").Range("I3")
Project_path = project_dir & "\" & Project_spec
On Error Resume Next
ChDir "Project_path"
If Err < 0 Then MkDir "Project_path"







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Creating a Directory from a user input

Hi mathew

When I use your code I have no problems?

Sub test()
Dim project_dir As String
Dim Project_spec As String
Dim Project_path As String

project_dir = Worksheets("Road Editor").Range("G4")
Project_spec = Worksheets("Road Editor").Range("I3")
Project_path = project_dir & "\" & Project_spec

On Error Resume Next
ChDir Project_path
If Err < 0 Then
MkDir Project_path
On Error GoTo 0
Else
'do nothing
End If
ChDir Application.DefaultFilePath
End Sub

If you use .value do you have the same problem then
project_dir = Worksheets("Road Editor").Range("G4").Value
Project_spec = Worksheets("Road Editor").Range("I3").Value



--
Regards Ron de Bruin
http://www.rondebruin.nl


"mathew" wrote in message ...
Ron: Sorry, my writing skills are not adequate. I can only tell you that I'm a proud graduate of many different public schools.
What I should have said is:
I did leave off the " " on testfolder!
To answer your question: No the line does not work when I put in the sub routine. However, the code below works, but is not

functional the way I need it to be! I need the user to input the directory path and the file name in separate cells on a worksheet.
This file will be used by many different users on different systems. Any help would be greatly appreciated!


"mathew" wrote:

Ron: Thank you very much for the help!
I did leave off the " " on testfolder!
To answer your question: No the line does not works when I put in the sub routine. However, the code below works, but is not

functional the way I need it to be! I need the user to input the path as the file name. This file will be used by many different
users on different systems. Any help would be appreciated.

On Error Resume Next
ChDir "C:\Network_2000\Current_projects\Network files"
If Err < 0 Then MkDir "C:\Network_2000\Current_projects\Network files"

"Ron de Bruin" wrote:

Hi mathew

and in I3 "Testfolder"
I assume that you leave out the "" ""

Is it working with this line
Project_path = "C:\Data\Testfolder"



--
Regards Ron de Bruin
http://www.rondebruin.nl


"mathew" wrote in message ...
Ron: I can't get it to work. I can get my code to work when I type the path into my statements.
This line:
fs.CreateFolder Project_path
is in yellow.

The Project_path is correct, but the line does not execute. Do I have some setting wrong? I used your values in G4 C:\Data

Like
yours the Data folder already exists
and in I3 "Testfolder"
Any suggestions would be welcom,ed! Thanks so much for your help!

"Ron de Bruin" wrote:

Hi

This is working for me with in G4 "C:\Data" (The Data folder already exist)
and in I3 "Testfolder"

Sub MakeDirectory()
Dim project_dir As String
Dim Project_spec As String
Dim Project_path As String
Dim fs As Object

Set fs = CreateObject("Scripting.FileSystemObject")

project_dir = Worksheets("Road Editor").Range("G4")
Project_spec = Worksheets("Road Editor").Range("I3")
Project_path = project_dir & "\" & Project_spec

If Not fs.FolderExists(Project_path) Then
fs.CreateFolder Project_path
Else
' do nothing
End If
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"mathew" wrote in message ...
I need to check to see if a directory exists and if it does not then create it. I can do this when I specify the

directory in
the
last two lines of the VB sub-routine, however, I need to get the path statement from 2 different user input cells on the
worksheet.
Here is what I have. Can you please help!

Dim project_dir As String
Dim Project_spec As String
Dim Project_path As String

project_dir = Worksheets("Road Editor").Range("G4")
Project_spec = Worksheets("Road Editor").Range("I3")
Project_path = project_dir & "\" & Project_spec
On Error Resume Next
ChDir "Project_path"
If Err < 0 Then MkDir "Project_path"









  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Creating a Directory from a user input

Ron: Thank you very much for the help!
I think I understand the problem. The MkDir statement wont function with the
\ in the path statement at least on this computer. Im not sure why. Any ideas? Here is the code that I used.

Sub Save_file_again()
'
' Save_file_again Macro
' Macro written on 7/12/2004 by Mathew '
'+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
'This declares the variables
'+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++

Dim pname As String
Dim fname As String
pname = Worksheets("Road Editor").Range("I4")
fname = Worksheets("Road Editor").Range("I3")
pathname = "C:\Network_2000\Current_Projects" 'Default Directory "C:\Network_2000\Current_Projects"

'+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
'This is a test to see if the Path was input by the user. If no path input then the directory
'C:\Network_2000\Current_Projects\ will be created. The MkDir command will not create multi-level directories so I used extra lines of code
'+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++

If Len(Range("I4")) < 1 Then
MsgBox "You did not enter a Path name. The File will be saved in C:\Network_2000\Current_Projects\SALE NAME YOU FILLED IN, Please look under File Properties for the file path!", vbOKOnly, "Look in C:\Network_2000\Current_Projects"
On Error Resume Next
ChDir pathname
If Err < 0 Then
'On Error Resume Next
'MkDir "C:\Network_2000\Current_Projects"
MkDir "C:\Network_2000"
ChDir "C:\Network_2000"
MkDir "Current_Projects"
ChDir pathname
End If

'+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
'This sub routine checks to see if the User Directory already exists on the computer:
'if it does already exist, it changes it to the active directory, or;
'if it does not exist it creates it and it changes it to the active directory.
'+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++

Else
On Error Resume Next
ChDir pname
If Err < 0 Then
MsgBox "The File will be saved in C:\Network_2000\Current_Projects\PATH NAME YOU FILLED IN, Please look under File Properties for the file path!", vbOKOnly, "User Directory being created!"
MkDir "C:\Network_2000"
ChDir "C:\Network_2000"
MkDir "Current_Projects"
ChDir "C:\Network_2000\Current_Projects"
MkDir pname
ChDir pname
End If
End If

'+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++
'This is a test to see if the user put in a file name. If it does not exist the Macros gives a
' message box and then stops. The ELSE part adds the date to the file name.
'+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++

If Len(Range("I3")) < 1 Then
MsgBox "Please name the Sale! And - Please try again!", vbOKOnly, "Can't Save"
Exit Sub
Else
If fname = Worksheets("Road Editor").Range("I3") Then
fname = fname & "_" & Format(Now, "mm-dd-yyyy") & ".xls"
Else
fname = Worksheets("Road Editor").Range("I3").Value & "_" & Format(Now, "mm-dd-yyyy") & ".xls"
End If
End If

'+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++
'This turns off the alerts like files save as msg box. It then saves the file
' turns the alerts back on and then the Macros ends.
'+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="" & fname & ""
Application.DisplayAlerts = True

End Sub




"Ron de Bruin" wrote:

Hi mathew

When I use your code I have no problems?

Sub test()
Dim project_dir As String
Dim Project_spec As String
Dim Project_path As String

project_dir = Worksheets("Road Editor").Range("G4")
Project_spec = Worksheets("Road Editor").Range("I3")
Project_path = project_dir & "\" & Project_spec

On Error Resume Next
ChDir Project_path
If Err < 0 Then
MkDir Project_path
On Error GoTo 0
Else
'do nothing
End If
ChDir Application.DefaultFilePath
End Sub

If you use .value do you have the same problem then
project_dir = Worksheets("Road Editor").Range("G4").Value
Project_spec = Worksheets("Road Editor").Range("I3").Value



--
Regards Ron de Bruin
http://www.rondebruin.nl


"mathew" wrote in message ...
Ron: Sorry, my writing skills are not adequate. I can only tell you that I'm a proud graduate of many different public schools.
What I should have said is:
I did leave off the " " on testfolder!
To answer your question: No the line does not work when I put in the sub routine. However, the code below works, but is not

functional the way I need it to be! I need the user to input the directory path and the file name in separate cells on a worksheet.
This file will be used by many different users on different systems. Any help would be greatly appreciated!


"mathew" wrote:

Ron: Thank you very much for the help!
I did leave off the " " on testfolder!
To answer your question: No the line does not works when I put in the sub routine. However, the code below works, but is not

functional the way I need it to be! I need the user to input the path as the file name. This file will be used by many different
users on different systems. Any help would be appreciated.

On Error Resume Next
ChDir "C:\Network_2000\Current_projects\Network files"
If Err < 0 Then MkDir "C:\Network_2000\Current_projects\Network files"

"Ron de Bruin" wrote:

Hi mathew

and in I3 "Testfolder"
I assume that you leave out the "" ""

Is it working with this line
Project_path = "C:\Data\Testfolder"



--
Regards Ron de Bruin
http://www.rondebruin.nl


"mathew" wrote in message ...
Ron: I can't get it to work. I can get my code to work when I type the path into my statements.
This line:
fs.CreateFolder Project_path
is in yellow.

The Project_path is correct, but the line does not execute. Do I have some setting wrong? I used your values in G4 C:\Data

Like
yours the Data folder already exists
and in I3 "Testfolder"
Any suggestions would be welcom,ed! Thanks so much for your help!

"Ron de Bruin" wrote:

Hi

This is working for me with in G4 "C:\Data" (The Data folder already exist)
and in I3 "Testfolder"

Sub MakeDirectory()
Dim project_dir As String
Dim Project_spec As String
Dim Project_path As String
Dim fs As Object

Set fs = CreateObject("Scripting.FileSystemObject")

project_dir = Worksheets("Road Editor").Range("G4")
Project_spec = Worksheets("Road Editor").Range("I3")
Project_path = project_dir & "\" & Project_spec

If Not fs.FolderExists(Project_path) Then
fs.CreateFolder Project_path
Else
' do nothing
End If
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"mathew" wrote in message ...
I need to check to see if a directory exists and if it does not then create it. I can do this when I specify the

directory in
the
last two lines of the VB sub-routine, however, I need to get the path statement from 2 different user input cells on the
worksheet.
Here is what I have. Can you please help!

Dim project_dir As String
Dim Project_spec As String
Dim Project_path As String

project_dir = Worksheets("Road Editor").Range("G4")
Project_spec = Worksheets("Road Editor").Range("I3")
Project_path = project_dir & "\" & Project_spec
On Error Resume Next
ChDir "Project_path"
If Err < 0 Then MkDir "Project_path"










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
Validation of input against the active directory Sing Chung[_2_] Excel Worksheet Functions 1 July 23rd 09 04:19 PM
Have user input converted to uppercase in same cell as input? Shannonn New Users to Excel 1 June 20th 06 03:19 AM
Help creating link & formula from user input bturner2 Excel Programming 2 June 9th 04 07:19 PM
CODE to select range based on User Input or Value of Input Field Sandi Gauthier Excel Programming 4 December 8th 03 03:22 PM
specify an input directory with GetOpenFilename Valeria[_2_] Excel Programming 2 November 25th 03 05:32 PM


All times are GMT +1. The time now is 01:21 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"