View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
asmenut asmenut is offline
external usenet poster
 
Posts: 59
Default Trouble renaming Folders

Last week I posted a question about moving and renaming of folders and files
(Moving A Folder 10/24/04). This procedure works great if the StrFromPath
variable is in the following format ("C:\testme1"). It does not seem to
work if I use a variable in the path ("C:\" & StrName). The code below shows
the method in which I am trying to accomplish this. I am using a
label.caption as the variable. Every time I go to set the objFolder I get a
"Path not found", which cause an "Object not set" when defining the new
name... Very frustrating.
I am referencing both the Runtime Library and the Script Object 1.0.

Any ideas? Please?

Sub RenameFolder()
Dim StrPath As String
Dim StrName As String
Dim NewName As String
Dim Fso As New FileSystemObject
Dim objFolder As Scripting.Folder
Dim objFile As Scripting.File

On Error Resume Next

Set Fso = New Scripting.FileSystemObject

StrName = F_Admin.LabelEO.Caption

StrPath = " C:\Documents and Settings\" & fOSUserName & "\My Documents\excel
****\New_EO\Pending EOs\" & StrName
Set objFolder = Fso.GetFolder(StrPath)

NewName = Right(StrName, Len(StrName) - 1)

objFolder.Name = NewName
objFile.Name = NewName

Set objFso = Nothing
Set objFolder = Nothing
Set objFile = Nothing

End Sub