So they need creating? Why not give all information when you ask the question?
MOVE FOLDER TO FOLDER OTHER
- omri_k
- Thread is marked as Resolved.
-
-
-
Sorry, yes they should be created by column D
-
hii roy
have you solution for me?
-
When I get time.
-
Thank you very much
-
Sorry about the delay, but I've had a really hectic week.
Try this, I haven't tested it so let me know if it needs any amendments.
Code
Display MoreOption Explicit Sub MoveToFolders() Dim ref As Object, CheckRefEnabled As Boolean Dim rRng As Range, rCl As Range Const MainFldr As String = "\\filesrv\users\omri\Desktop\TEST\" ''/// add reference toScripting Library CheckRefEnabled = 0 With ThisWorkbook For Each ref In .VBProject.References If ref.Name = "Scripting" Then CheckRefEnabled = 1 Exit For End If Next ref If CheckRefEnabled = 0 Then .VBProject.References.AddFromGuid "{420B2830-E718-11CF-893D-00A0C9054228}", 1, 0 End If End With Set FSO = CreateObject("Scripting.FileSystemObject") Set Rng = Sheets("SW1").Range("A1").CurrentRegion ''/// create sub folders if needed For Each rCl In rRng.Columns(7).Cells If Not FSO.FileExists(MainFldr & rCl.Value) Then FSO.CreateFolder (MainFldr & rCl.Value) Next rCl ''/// move the files For Each rCl In rRng.Columns(4).Cells If FSO.FileExists("MainFldr & rCl.Value" & ".pdf") Then FSO.MoveFile "MainFldr & rCl.Value" & ".pdf", MainFldr & rCl.Offset(, 3).Value & Application.PathSeparator & rCl.Value & ".pdf" ElseIf FSO.FileExists("MainFldr & rCl.Value" & ".step") Then FSO.MoveFile "MainFldr & rCl.Value" & ".pdf", MainFldr & rCl.Offset(, 3).Value & Application.PathSeparator & rCl.Value & ".step" End If Next rCl Set FSO = Nothing Set rRng = Nothing Set rCl = Nothing End Sub
-
HI Roy,
There is an error running,
He does not recognize FSO
-
The code that I posted sets the reference to the FSO. Attach your workbook with my code added
-
-
As I said, attach the workbook. An image cannot be tested!
-
this the worksheet
-
There was some missing variables. If you want to learn VBA try looking what errors mean on Google.
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!