#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default .movefile

Hello all.

Well, I'm a little closer than before, but still short of my goal.

We've found a macro that Ron DeBruin posted on his website last year and
have found that it works for our purposes, all but one item.

In his code, the FSO.MoveFile moves the entire directory's contents with the
specified file extension-- in this case, xl*.

Based on another poster's comments, and what I'd read in the help files,
msdn libraries, etc.... that MoveFile would move an open file. However, with
Ron's code this does not happen. I get a "permission denied" error. Which is
a Run time error # 70.

Which, if I understand correctly, occurs due to an attempt to move a file
which is open.

Our goal is to move only files that have thrown an error, and then return to
the processes we were running prior to finding the error.

This requires that the file name be a variable to store the name of the file
being operated on (by other macros in our routine).

It also appears to require emptying the file name once it is complete moving
that particular file.

And based on the 70 error, we'd need to close the file first- while
maintaining its name in the variable.

Thus far, the variables I've seen only maintain the file's name in its
memory as long as the file is pending an operation, and once that process is
complete, the file name being stored is deleted from memory.

So, if I understand this correctly, how would I accomplish the goals of:
1- making a variable that would maintain the file name in which an error
occurs, after closing the file.
2- moving only the file in which we found the particular error?

Here's Ron DeBRuin's macro.
----------------------------------------

Sub Move_Certain_Files_To_New_Folder()
'This example move all Excel files from FromPath to ToPath.
'Note: It will create the folder ToPath for you with a date-time stamp
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String

FromPath = "C:\Users\Ron\Data" '<< Change
ToPath = "C:\Users\Ron\" & Format(Now, "yyyy-mm-dd h-mm-ss") _
& " Excel Files" & "\" '<< Change only the destination folder

FileExt = "*.xl*" '<< Change
'You can use *.* for all files or *.doc for word files

If Right(FromPath, 1) < "\" Then
FromPath = FromPath & "\"
End If

FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "No files in " & FromPath
Exit Sub
End If

Set FSO = CreateObject("scripting.filesystemobject")

FSO.CreateFolder (ToPath)

FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "You can find the files from " & FromPath & " in " & ToPath

End Sub
--------------------------------------------------------

Thank you for your helps.
Best,
SteveB.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default .movefile

You should be able to store the file name in a variable after you open the
file, then close the file and the variable should still have the file name.
You cannot, however, use the same scripting object variable that you
originally used to open the file, because it will go away when the file is
closed. I would suggest that when you store it that you use the full name
(include the path).

"SteveDB1" wrote:

Hello all.

Well, I'm a little closer than before, but still short of my goal.

We've found a macro that Ron DeBruin posted on his website last year and
have found that it works for our purposes, all but one item.

In his code, the FSO.MoveFile moves the entire directory's contents with the
specified file extension-- in this case, xl*.

Based on another poster's comments, and what I'd read in the help files,
msdn libraries, etc.... that MoveFile would move an open file. However, with
Ron's code this does not happen. I get a "permission denied" error. Which is
a Run time error # 70.

Which, if I understand correctly, occurs due to an attempt to move a file
which is open.

Our goal is to move only files that have thrown an error, and then return to
the processes we were running prior to finding the error.

This requires that the file name be a variable to store the name of the file
being operated on (by other macros in our routine).

It also appears to require emptying the file name once it is complete moving
that particular file.

And based on the 70 error, we'd need to close the file first- while
maintaining its name in the variable.

Thus far, the variables I've seen only maintain the file's name in its
memory as long as the file is pending an operation, and once that process is
complete, the file name being stored is deleted from memory.

So, if I understand this correctly, how would I accomplish the goals of:
1- making a variable that would maintain the file name in which an error
occurs, after closing the file.
2- moving only the file in which we found the particular error?

Here's Ron DeBRuin's macro.
----------------------------------------

Sub Move_Certain_Files_To_New_Folder()
'This example move all Excel files from FromPath to ToPath.
'Note: It will create the folder ToPath for you with a date-time stamp
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String

FromPath = "C:\Users\Ron\Data" '<< Change
ToPath = "C:\Users\Ron\" & Format(Now, "yyyy-mm-dd h-mm-ss") _
& " Excel Files" & "\" '<< Change only the destination folder

FileExt = "*.xl*" '<< Change
'You can use *.* for all files or *.doc for word files

If Right(FromPath, 1) < "\" Then
FromPath = FromPath & "\"
End If

FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "No files in " & FromPath
Exit Sub
End If

Set FSO = CreateObject("scripting.filesystemobject")

FSO.CreateFolder (ToPath)

FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "You can find the files from " & FromPath & " in " & ToPath

End Sub
--------------------------------------------------------

Thank you for your helps.
Best,
SteveB.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default .movefile

Hi JLG,
Thanks for the response.
So instead of my FSO variable, I'd need to dim/use another scripting
variable to maintain that file name?
In which case, would it then be possible to just choose a new name for say,
FNames to retain the file name? Or since it's based on FNames, would it then
be emptied when I close the file?


"JLGWhiz" wrote:

You should be able to store the file name in a variable after you open the
file, then close the file and the variable should still have the file name.
You cannot, however, use the same scripting object variable that you
originally used to open the file, because it will go away when the file is
closed. I would suggest that when you store it that you use the full name
(include the path).

"SteveDB1" wrote:

Hello all.

Well, I'm a little closer than before, but still short of my goal.

We've found a macro that Ron DeBruin posted on his website last year and
have found that it works for our purposes, all but one item.

In his code, the FSO.MoveFile moves the entire directory's contents with the
specified file extension-- in this case, xl*.

Based on another poster's comments, and what I'd read in the help files,
msdn libraries, etc.... that MoveFile would move an open file. However, with
Ron's code this does not happen. I get a "permission denied" error. Which is
a Run time error # 70.

Which, if I understand correctly, occurs due to an attempt to move a file
which is open.

Our goal is to move only files that have thrown an error, and then return to
the processes we were running prior to finding the error.

This requires that the file name be a variable to store the name of the file
being operated on (by other macros in our routine).

It also appears to require emptying the file name once it is complete moving
that particular file.

And based on the 70 error, we'd need to close the file first- while
maintaining its name in the variable.

Thus far, the variables I've seen only maintain the file's name in its
memory as long as the file is pending an operation, and once that process is
complete, the file name being stored is deleted from memory.

So, if I understand this correctly, how would I accomplish the goals of:
1- making a variable that would maintain the file name in which an error
occurs, after closing the file.
2- moving only the file in which we found the particular error?

Here's Ron DeBRuin's macro.
----------------------------------------

Sub Move_Certain_Files_To_New_Folder()
'This example move all Excel files from FromPath to ToPath.
'Note: It will create the folder ToPath for you with a date-time stamp
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String

FromPath = "C:\Users\Ron\Data" '<< Change
ToPath = "C:\Users\Ron\" & Format(Now, "yyyy-mm-dd h-mm-ss") _
& " Excel Files" & "\" '<< Change only the destination folder

FileExt = "*.xl*" '<< Change
'You can use *.* for all files or *.doc for word files

If Right(FromPath, 1) < "\" Then
FromPath = FromPath & "\"
End If

FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "No files in " & FromPath
Exit Sub
End If

Set FSO = CreateObject("scripting.filesystemobject")

FSO.CreateFolder (ToPath)

FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "You can find the files from " & FromPath & " in " & ToPath

End Sub
--------------------------------------------------------

Thank you for your helps.
Best,
SteveB.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default .movefile

I'm not sure how you are calling out the files but whatever you use to
represent the file collection in a directory, you could use the index number
to get he name, as an example:

myVarName = fs.Path & "\" & fNames(1).Name

Where if fNames is the files collection in the fs Object, the fNames(1)
would be the first file in that collection and the myVarName variable would
store that name, even after the fs Object is gone.

"SteveDB1" wrote:

Hi JLG,
Thanks for the response.
So instead of my FSO variable, I'd need to dim/use another scripting
variable to maintain that file name?
In which case, would it then be possible to just choose a new name for say,
FNames to retain the file name? Or since it's based on FNames, would it then
be emptied when I close the file?


"JLGWhiz" wrote:

You should be able to store the file name in a variable after you open the
file, then close the file and the variable should still have the file name.
You cannot, however, use the same scripting object variable that you
originally used to open the file, because it will go away when the file is
closed. I would suggest that when you store it that you use the full name
(include the path).

"SteveDB1" wrote:

Hello all.

Well, I'm a little closer than before, but still short of my goal.

We've found a macro that Ron DeBruin posted on his website last year and
have found that it works for our purposes, all but one item.

In his code, the FSO.MoveFile moves the entire directory's contents with the
specified file extension-- in this case, xl*.

Based on another poster's comments, and what I'd read in the help files,
msdn libraries, etc.... that MoveFile would move an open file. However, with
Ron's code this does not happen. I get a "permission denied" error. Which is
a Run time error # 70.

Which, if I understand correctly, occurs due to an attempt to move a file
which is open.

Our goal is to move only files that have thrown an error, and then return to
the processes we were running prior to finding the error.

This requires that the file name be a variable to store the name of the file
being operated on (by other macros in our routine).

It also appears to require emptying the file name once it is complete moving
that particular file.

And based on the 70 error, we'd need to close the file first- while
maintaining its name in the variable.

Thus far, the variables I've seen only maintain the file's name in its
memory as long as the file is pending an operation, and once that process is
complete, the file name being stored is deleted from memory.

So, if I understand this correctly, how would I accomplish the goals of:
1- making a variable that would maintain the file name in which an error
occurs, after closing the file.
2- moving only the file in which we found the particular error?

Here's Ron DeBRuin's macro.
----------------------------------------

Sub Move_Certain_Files_To_New_Folder()
'This example move all Excel files from FromPath to ToPath.
'Note: It will create the folder ToPath for you with a date-time stamp
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String

FromPath = "C:\Users\Ron\Data" '<< Change
ToPath = "C:\Users\Ron\" & Format(Now, "yyyy-mm-dd h-mm-ss") _
& " Excel Files" & "\" '<< Change only the destination folder

FileExt = "*.xl*" '<< Change
'You can use *.* for all files or *.doc for word files

If Right(FromPath, 1) < "\" Then
FromPath = FromPath & "\"
End If

FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "No files in " & FromPath
Exit Sub
End If

Set FSO = CreateObject("scripting.filesystemobject")

FSO.CreateFolder (ToPath)

FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "You can find the files from " & FromPath & " in " & ToPath

End Sub
--------------------------------------------------------

Thank you for your helps.
Best,
SteveB.

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
FSO.MoveFile SteveDB1 Excel Programming 13 May 12th 09 05:02 PM
Help!!! MoveFile Method CAM Excel Programming 3 October 11th 06 03:13 AM
Movefile "Permission Denied" Gordon Gecko[_2_] Excel Programming 0 June 9th 05 08:44 PM
MoveFile problems [email protected] Excel Programming 1 December 28th 04 03:24 PM
How to maintain the original date and time for the MoveFile command Wellie Excel Programming 0 March 3rd 04 03:33 AM


All times are GMT +1. The time now is 01:00 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"