Move documents from one folder to another...

AndyD

Active Member
Joined
Nov 14, 2002
Messages
449
Hi I want to move pdfs from older folder to another: for example:

from C:/folder 1 to C:/folder 2

How do I do this?

Regards

Andy
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,304
Office Version
  1. 365
Platform
  1. Windows
Andy

Can't you just open Windows Explorer, goto folder 1, select all the files required, right click, select cut, goto folder 2, right click and select paste?

Or am I missing something?:)
 

AndyD

Active Member
Joined
Nov 14, 2002
Messages
449
Hi
that would work fine however I want to suggest this as alternative as there are actually a large number of folders

Andy
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,304
Office Version
  1. 365
Platform
  1. Windows
Andy

So do you want to do this in code?

If so you probably want to look at the following.

1 The Name statement.

2 The FileCopy statement.

3 The File System Object.

The first 2 will work with individual files, but could work in a loop.

I think, but I'm not 100% sure, that with the 3rd you could move multiple files in one go.

Can you give more details of what you actually want to do?
 

AndyD

Active Member
Joined
Nov 14, 2002
Messages
449

ADVERTISEMENT

hi
what I want to be able to do is for users to click on a button called, for example, "Move from folder 1 to folder" and for the macro to move all documents to the appropriate folder.

The next stage would be for the user to move from folder 2 to folder 3 etc, etc

Hope makes sense

Cheers

Andy
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,304
Office Version
  1. 365
Platform
  1. Windows
Andy

But where do you want to do this?

This is an Excel forum, but you've not mentioned Excel so far.:)
 

AndyD

Active Member
Joined
Nov 14, 2002
Messages
449

ADVERTISEMENT

Sorry...

:biggrin:

In a excel worksheet, user presses on a button that says for example "Move documents to folder 2"....

Pressing this moves the documents in folder 1 to folder 2

I know it can be done as seen it before (and I can't find by searching)

Can you help?

Cheers

Andy
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,304
Office Version
  1. 365
Platform
  1. Windows
Andy

Here's one way.
Code:
Sub Test()
Dim strSrcDir As String
Dim strDstDir As String
Dim I As Long

    strSrcDir = "C:\Folder1\"
    strDstDir = "C:\Folder2\"
    
    With Application.FileSearch
        .NewSearch
        .LookIn = strSrcDir
        .FileType = msoFileTypeAllFiles
        .Execute
        For I = 1 To .FoundFiles.Count
            Name (.FoundFiles(I)) As strDstDir & Dir(.FoundFiles(I))
        Next I
    End With

End Sub
If you paste this in a module (Insert>Module) in the VBA editor (ALT+F11) you can then add a button to a worksheet and assign the code to it using Assign macro...
 

Forum statistics

Threads
1,141,681
Messages
5,707,796
Members
421,528
Latest member
datdude151

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top