opening folders within a folder

J

JT

I have a template in each cost center's folder on a corporate drive.
Occassionally, I will need to replace those templates in each folder due to
fixes, enhancements, etc. I'm looking to write a macro that will go though
each cost center folder, open it, delete the existing template, copy the new
template into the cost center folder, and then move to the next cost center
and repeat these steps.

I can delete the template and copy the new one in but I'm having trouble
cycling though the cost center folders.

Following is the drive and a sampling of the cost center folders that I need
to cycle through. I'm only showing a few but when this is fully implemented
I could have to replace 150 or templates and I don't want to do this one by
one.

P:\Accounts Receivable\Cost Centers\10A
P:\Accounts Receivable\Cost Centers\15C
P:\Accounts Receivable\Cost Centers\21D
P:\Accounts Receivable\Cost Centers\33A

Any help with the code to cycle through all of the folders within the "Cost
Centers" and open each cost center folder would be greatly appreciated.

Thanks for the help......
 
D

Don Guillett

Look in the vba help index for NAME. It will actually MOVE the files.
Name Statement Example
This example uses the Name statement to rename a file. For purposes of this
example, assume that the directories or folders that are specified already
exist. On the Macintosh, “HD:†is the default drive name and portions of the
pathname are separated by colons instead of backslashes.

Dim OldName, NewName
OldName = "OLDFILE": NewName = "NEWFILE" ' Define file names.
Name OldName As NewName ' Rename file.

OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName ' Move and rename file.
 
J

Jim Thomlinson

Here is some code to travese all of the folders and subfolders...(original
from Bob Phillips)

' ***********************************************************
Sub CallingProc()
Dim strPath As String
Dim fso As Object
Dim oDir As Object

strPath = "P:\Accounts Receivable\Cost Centers"
Set fso = CreateObject("Scripting.FileSystemObject")
Set oDir = fso.getfolder(strPath)
PrintFolderName oDir

Set fso = Nothing
Set oDir = Nothing
End Sub

' ***********************************************************
Sub PrintFolderName(Dir As Object)
Dim fSubDir As Object

' Supposed to be recursive...
' Print the folder name.
Debug.Print Dir.Name
' Check subfolders recursively.
For Each fSubDir In Dir.SubFolders
PrintFolderName fSubDir
Next fSubDir
End Sub
 

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