• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Need Help : VBA Create folders

Mahantesh

Member
Hi Team,

Please help me in solving this tricky situation.

I have userform Where i browse a folder which has 10 files to be processed and save these files with different filenames.

Now here is the tricky part:
------------------------------
After processing, I would like to create new temp folder in the same folder where i would store old 10 files.

Now, next time i would just delete the old 10 files(not files in the temp created) and paste new set 10 files. After processing again move these old 10 files to Temp folder. HERE DO NOT CREATE NEW TEMP folder again as it is created yesterday.

Eg: C:\ABC has 10 files. after processing these files would be moved to C:\ABC\TEMP.

Now tomorrow if i run again i just want to process files and move the files to TEMP folder without creating folder again. i.e Just move the files to TEMP folder

Please help!

Regards,
Mahantesh
 
You can check if directory exist before creating like below:
Code:
Public Sub ChkDirExist()
Dim strFldPath As String
strFldPath = "C:\Temp" '\\Set path here
If Len(Dir(strFldPath, vbDirectory)) > 0 Then
  MsgBox "Directory " & strFldPath & " exists!", vbInformation
Else
  MsgBox "Directory " & strFldPath & " doesn't exist!", vbInformation
  MkDir strFldPath
End If
End Sub
 
Hi Shri,

Thank you for the reply.

I am able to create the folder but what i need to if i have TEMP(e.g) folder, tomorrow i would like to move my rawdata all files to TEMP folder without creating the folder again. or is there anything to just overwrite the folder with the same name
Regards,
Mahantesh
 
Hello Mahesh.

Little confusion...When processing 10 files in C: drive...why do you want to move to Temp folder...Why dont' you process 10 files in temp itself..

Let me know if i have understood clearly!
 
Hi Shri,

Thank you for the reply.

I am able to create the folder but what i need to if i have TEMP(e.g) folder, tomorrow i would like to move my rawdata all files to TEMP folder without creating the folder again. or is there anything to just overwrite the folder with the same name
Regards,
Mahantesh
Hi, Mahantesh!
Code provided by shrivallabha does the job or folder creation. Please note that MdDir function is in the part of the If...Then...Else construction that is executed when it (the temp folder) doesn't exist.
You should adapt that code, surely removing both message boxes and embed it in your code or build your code around it.
Regards!
 
Back
Top