Thread: FSO.MoveFile
View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Steve Yandl Steve Yandl is offline
external usenet poster
 
Posts: 284
Default FSO.MoveFile

No problems for me although I downloaded it quite some time ago.

Steve Yandl

"SteveDB1" wrote in message
...
Hey Steve,
Have you had any problems viewing the help files in that chm file?
I downloaded it, and I just keep getting "page cannot be displayed"
responses.




"Steve Yandl" wrote:

Steve, you're welcome. On that scripting page, there are a couple of
help
files available for download. I find that Script56.CHM is a bit more
help
than the VBA help files when using FSO. I use it all the time. It may
make
life simpler down the road if you download it now.

Steve Yandl



"SteveDB1" wrote in message
...
Hi Steve,

I'll look into the scripting guy's page-- thank you.
I've already created the errorfiles' folder, so that's set. I will
however
ensure that I add that to our code.
Thank you for explaining the difference on .move, and .movefile. I was
looking at both and the difference wasn't explicitly stated.

And we'll look more closely at the split function.

Thank you for your helps.
Best,
SteveB.

"Steve Yandl" wrote:

Steve,

I don't have Excel 2007 so won't offer a complete solution, just a
couple
of
comments.

Be sure you're using FSO.MoveFile and not FSO.Move.

You can move open files with the filesystemobject's MoveFile method
although
I've never tested from a Workbook when the code was running from
within
the
workbook.

You probably want to check that the "\ErrorSaveFiles" subfolder exists
before you attempt to move the file there. If it doesn't exist, you
can
use
the file system object to create it and then move your file there.

In the line where you remove the extension from FName, you will run
into
problems if the file name contains any periods in addition to the one
setting off the file extension. Unless you're certain that won't
happen,
I'd use the 'Split' function with the period as the delimiter and then
reconstruct the array without the last member.

The "Scripting.FileSystemObject" is borrowed from scripting, so some
of
the
best help and examples will come from places that are dedicated to
scripting. For some decent examples that can easily be modified to
use
within VBA, check out
http://www.microsoft.com/technet/scr...r/default.mspx and take
the
link
named 'Hey Scripting Guy'.


Steve Yandl



"SteveDB1" wrote in message
...
Morning all.
I'm trying to modify an existing macro to move a file from its
source
to a
secondary folder if it finds an error, for later resolution.
I.e., I'm using an existing macro grouping to update a series of
workbooks
to make for a common format for all our files, then if it finds an
error
in
any of the files, we want to move it from the source location to a
"errorfolder" destination for later processing/fixing.
The goal is to set aside the files that have errors so we can just
focus
on
"healthy" files, so we're not constantly having to start/stop and
then
retrace our steps.


We've been trying the FSO.Move
And we keep getting either 438 or 450 errors.


1- What would we need to modify out of the code below to resolve
this?
We're
using Excel 2007.

2- can we move an open file or do we need to close the file first,
and
then
move it?
(I know, stupid question, but this is our first use of this method)


-----------------------------------------------------

Sub ASaveErrorToSubFolder()
'same routine as AsaveNewFormat but when any errors found will
save
to
the
'\ErrorSaveFiles subfolder

With Application
.DisplayAlerts = True 'these can be changed to either true or
false,
depending
'on if you want the alerts or not.
.ScreenUpdating = True 'Prevents from having to watch updating of
files.
End With

Folder = ActiveWorkbook.Path 'this sets the folder of the source
file

FName = ActiveWorkbook.Name 'this looks at the existing file's name

'remove extension
FName = Left(FName, InStr(FName, ".") - 1) ' this appears to remove
the
existing
'file's extension

SaveName = Folder & "\ErrorSaveFiles\" & FName & ".xlsx" ' this
tells
where
to
'save it, but one directory deeper.
' if you wish to have it save to another directory, you must specify
that
directory. xx



On Error Resume Next 'This bypasses an error to keep the routine
moving.

ActiveWorkbook.SaveAs Filename:=SaveName,
FileFormat:=xlOpenXMLWorkbook


With ActiveWorkbook 'this command grouping is to save workbook after
processing
'is completed,

.Save 'do a READ ONLY SaveAS, and close the workbook.
.ChangeFileAccess Mode:=xlOpenXMLWorkbook 'xlReadOnly xx
'.Close 'comment for now, other macro closes wkbk.

End With
End Sub
--------------------------------------------------------------------------------------

Thank you.
Best,
SteveB.