View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default Trouble renaming Folders

you dont give a clue as to the values of the variables.
AND you assume that all users (designated by the fOSUserName variable )
have an 'excel ****' folder in their my documents path..

Also you should be aware of any OPEN files.. before renaming a folder.

THEN you rename the FOLDER before the file..
I'd do it the other way..
First rename the file THEN the folder.

For debugging:
Open the LOCALS window
Step thru your code with F8
look at the locals window to see what the object and string variables
contain when your code is running.


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"?B?YXNtZW51dA==?=" wrote :

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