Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to detect if folder exists if not create it using a variable 1

Status
Not open for further replies.

advox1

Technical User
Nov 28, 2003
26
0
0
GB
Hi

I need to go to the last entry in a column and use this as myVar. I then need to check if a folder exsists with this name, and if it does not, create one.

Then move up the list until I get to the point where the variable does exist within the folder name and exit.

I have managed to do the code for creating the folder, but I am stuck on the code to check if this folder exists first or not and exiting if it does.

The code so far is:-

Dim myVar As String
Dim mPath As String
myVar = ActiveCell.Value
mPath = "P:\Spreadsheet Project\Testfolder\04_" & myVar
MkDir mPath
'will copy time & disb workbook into new folder
filecopy "P:\Spreadsheet Project\Time\Trial Sheet.xls", "P:\Spreadsheet Project\Testfolder\04_" & myVar & "\Trial Sheet.xls"
End Sub

Can anyone help?

Thanks

Jo
 
Something like this ?
Set fso = CreateObject("Scripting.FileSystemObject")
If Not (fso.FolderExists(mPath)) Then
MkDir mPath
End If
FileCopy "P:\Spreadsheet Project\Time\Trial Sheet.xls", mPath & "\Trial Sheet.xls"
Set fso = Nothing

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
You're almost there
[tt]
mPath = "P:\Spreadsheet Project\Testfolder\04_" & myVar
If Dir(mPath, 16) = "" Then MkDir mPath
[/tt]
 
Thanks Golom

Have just tried your code and works great!

Jo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top