Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Changing directory names

Hi Karen,

Assume the old folder names are in A2:A10 and the new names are in B2:B10,

Try:
'===============
Public Sub TryIt()
Dim rng As Range
Dim rcell As Range

Set rng = Range("A2:A10") '<<=== CHANGE

For Each rcell In rng.Cells
With rcell
If Not IsEmpty(.Value) Then
RenameFolder .Value, .Offset(0, 1).Value
End If
End With
Next rcell
End Sub
'<<===============

'===============
Public Function RenameFolder(sourceFolder As String, _
targetFolder As String)
On Error Resume Next
With CreateObject("Scripting.FileSystemObject")
.MoveFolder sourceFolder, targetFolder
End With
End Function
'<<===============

---
Regards,
Norman


"Karen Howie" wrote in message
...
Hi folks,

I'd like to write a macro which loops around a table in excel changing a
directory name (listed in one column) to another name (listed in a second
column). What is the command to change a directory name?

Thank-you!

Karen



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Changing directory names

Thank you both very much! I'll go away and have a play!

Thanks again

Karen

"Norman Jones" wrote:

Hi Karen,

Assume the old folder names are in A2:A10 and the new names are in B2:B10,

Try:
'===============
Public Sub TryIt()
Dim rng As Range
Dim rcell As Range

Set rng = Range("A2:A10") '<<=== CHANGE

For Each rcell In rng.Cells
With rcell
If Not IsEmpty(.Value) Then
RenameFolder .Value, .Offset(0, 1).Value
End If
End With
Next rcell
End Sub
'<<===============

'===============
Public Function RenameFolder(sourceFolder As String, _
targetFolder As String)
On Error Resume Next
With CreateObject("Scripting.FileSystemObject")
.MoveFolder sourceFolder, targetFolder
End With
End Function
'<<===============

---
Regards,
Norman


"Karen Howie" wrote in message
...
Hi folks,

I'd like to write a macro which loops around a table in excel changing a
directory name (listed in one column) to another name (listed in a second
column). What is the command to change a directory name?

Thank-you!

Karen




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
to convert all the file names in one directory to .xls? S.G.Pillai Excel Discussion (Misc queries) 2 September 27th 05 05:13 PM
Getting file names in a directory John Excel Programming 2 March 8th 05 03:38 PM
Creating a macro that lists directory names within a directory.... Andy Excel Programming 4 November 28th 04 06:13 AM
Aquiring Directory names aking1987[_7_] Excel Programming 1 November 16th 04 07:06 PM
Aquiring Directory names aking1987[_6_] Excel Programming 1 November 16th 04 01:45 PM


All times are GMT +1. The time now is 02:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"