Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
TROUBLE RENAMING A WORKSHEET IN EXCEL 2000 | Excel Worksheet Functions | |||
renaming | Excel Programming | |||
Renaming folders | Excel Programming | |||
Renaming | Excel Programming | |||
Renaming within VBA | Excel Programming |