Thread: Moving a folder
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
asmenut asmenut is offline
external usenet poster
 
Posts: 59
Default Moving a folder

Yep, that's the ticket. Thanks a million Jim. And thanks to all the MVP's
for their help. Time for this app to go to BETA. You Guys/Girls are the
best.

"Jim Cone" wrote:

John,

I just tried the following code and it worked for me...
(Note also that you can rename a file or folder using the Name statement in VBA)

'-----------------------------------------------
' Requires reference to "Microsoft Scripting Runtime" in the VBA project.
' Following code moves the Analysis folder from the Library folder to the C drive
' and renames the folder and its files.
' Jim Cone - October 24, 2004

Sub MoveFolderWithScriptingRuntime()
Dim strFromPath As String
Dim strToPath As String
Dim strName As String
Dim Fso As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim objFile As Scripting.File

Set Fso = New Scripting.FileSystemObject

'Specify path of folder to be moved.
strFromPath = "C:\Program Files\Microsoft Office\Office\Library\Analysis"
'Retain folder name in variable.
Set objFolder = Fso.GetFolder(strFromPath)
strName = objFolder.Name

'Specify new location for folder.
strToPath = "C:\"
'Move the folder.
Fso.MoveFolder strFromPath, strToPath

'Establish a reference to the folder in the new location.
Set objFolder = Fso.GetFolder(strToPath & "\" & strName)

'Skip this part if you only want to rename the folder
'Rename each file in the folder.
For Each objFile In objFolder.Files
objFile.Name = "X" & objFile.Name
Next 'objFile

'Rename the folder.
objFolder.Name = "X" & objFolder.Name

'Technically not required, but I prefer it.
Set objFolder = Nothing
Set objFile = Nothing
Set Fso = Nothing
End Sub
'-----------------------------------------------

Regards,
Jim Cone
San Francisco, CA

"asmenut" wrote in message ...
Thanks Jim. Works great. But, is there a way to rename the folder / file to
reflect a new location (i.e. E28802 - 28802). A little explanation might
help:

Once the file is authorized, the Log number is changed (so as to reflect the
approval of the Engineering Order) (Log Number E28802 - 28802). This folder
(once approved) will contain all the pertinent files required to process the
Order. When the file and folder is renamed and moved, the EO admin will be
able to set tracking options throughout the rest of the process (i.e.
routing, processing, archiving, etc)

John,


-snip-