PDA

View Full Version : [SOLVED:] Copy file from source path in cell, to destination path in cell, and create folders



ecalid
03-29-2023, 03:16 AM
Good morning,

I hope you are all well.

I am having extremely bad luck with my coding just lately, I am very much a beginner and a copy & paste expert (I'm not afraid to admit it).

I have hit a brick wall though.

Basically the company I work for needs me to create a portal in excel where managers can save files of their employees to their 'employee file'.

So I have made a sheet where they can select which file they want to save, which then generates a path in which the file will be saved to.

The issue I have is that I need the path to generate the associated folders (which will be their name), so then I do not need to add a new folder each time a new employee starts, this folder will automatically be created in the destination folder when they submit the file, which is then saved in the newly created folder.

Could anybody help me with this?

Any help you could provide would be greatly appreciated.

30695

Aussiebear
03-29-2023, 04:06 AM
Welcome to the VBAX forum eclaid.

arnelgp
03-29-2023, 04:35 AM
can you attach a sample excel file?

ecalid
03-29-2023, 04:57 AM
Hi guys,

Thank you for your reply and your welcome.

Please see below:

https://file.io/ShoUB71z3ptH


Thanks.

georgiboy
03-29-2023, 05:01 AM
Below is a small sub that checks if a folder exists, if not then it will create it:

Sub MakeMyFolder()
Dim fPath As String

fPath = "C:\Users\JoeBloggs\Desktop\TEST\George"

If Dir(fPath, vbDirectory) = "" Then
MkDir Path:=fPath
MsgBox "Done"
Else
MsgBox "found it"
End If
End Sub

Or another option:

Sub MakeMyFolder2()
Dim fPath As String
Dim fsoFSO

fPath = "C:\Users\clarkg\Desktop\TEST\George"

Set fsoFSO = CreateObject("Scripting.FileSystemObject")
If fsoFSO.FolderExists(fPath) Then
MsgBox "found it"
Else
fsoFSO.CreateFolder (fPath)
MsgBox "Done"
End If
End Sub

arnelgp
03-29-2023, 05:28 AM
you may also try this.

ecalid
03-29-2023, 05:41 AM
Wow! Thank you guys so much. This is exactly what I've needed.

Aussiebear
03-29-2023, 10:49 AM
ecalid, if you are happy with the solution please use the Thread Tools Option and select "Mark thread as Solved" ( to the top right of the very first post in this thread)