copy folder's files to a new nonexisting folder's subfolder

G

gil

Hello All,

I seek VBA code to copy all of folderX's files to a new non-existing folder's subfolder. The two lines below do not get me there.



Set fs = CreateObject("Scripting.FileSystemObject")

fs.copyFolder "C:\FolderX", "C:\FolderB\subFolderC"



Word 2003, Windows XP



Help appreciated as always. :)

Gil

http://www.TenSecondMedicalRecord.com
 
D

Doug Robbins - Word MVP

Use the mkDir command to create the folder. You can check for an error 76
when you use chDir when trying to change to the folder to determine if it
already exists.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP


Hello All,
I seek VBA code to copy all of folderX's files to a new non-existing
folder's subfolder. The two lines below do not get me there.

Set fs = CreateObject("Scripting.FileSystemObject")
fs.copyFolder "C:\FolderX", "C:\FolderB\subFolderC"

Word 2003, Windows XP

Help appreciated as always. :)
Gil
http://www.TenSecondMedicalRecord.com
 
G

gil

Hi Doug,

Thank you. I was running into a problem because I had named the macro itself MkDir. When I changed its name, it seemed to work
fine.



You're right, I'd like to know code for:

If does not exist, MkDir "c:\patients"



My code for copying a folder seems to work fine:

Set fs = CreateObject("Scripting.FileSystemObject")

fs.copyFolder "C:\TSMRunzipTemp", "C:\Patients\AMR"



Cheers,

Gil
 
D

Doug Robbins - Word MVP

On Error GoTo CreateFolder

ChDir "C:\patients"

CreateFolder:
If Err.Number = 76 Then
MkDir "C:\Patients"
Else
MsgBox "Some other error occured."
End If

'Rest of your code

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP

I probably should have included an Exit Sub after the MsgBox "Some other
error occurred"

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top