Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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



  #2   Report Post  
Posted to microsoft.public.excel.programming
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





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Trouble renaming Folders

Sorry about that. The path is to my development folder (hence fOSUsername
and "excel ****").
All files are saved and closed prior to any renaming conventions.
The variable required is the Log Number (i.e. E28802). Once the Right(...,
len()..) statement is executed, the log number becomes (28802). The Log
number is located on an existing userform (authorization) as a label. I use
the label.caption as a mocation for the number so that it will carry over
(i.e. F_Admin.LabelEO.Caption)
In this condition, even if I try to rename a file first, the error "Path
not found" shows it's ugly face. The problem is that the location (strPath)
is valid, it just won't attach to the Set objFolder statement.

"keepITcool" wrote:

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






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
TROUBLE RENAMING A WORKSHEET IN EXCEL 2000 Cat Excel Worksheet Functions 2 June 17th 06 05:38 PM
renaming No Name Excel Programming 1 October 11th 04 05:01 PM
Renaming folders Robin Clay[_3_] Excel Programming 6 August 12th 04 05:12 PM
Renaming ianripping[_66_] Excel Programming 3 May 22nd 04 12:02 PM
Renaming within VBA Brent McIntyre Excel Programming 4 August 21st 03 02:10 AM


All times are GMT +1. The time now is 01:10 PM.

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"