Thread: FSO.MoveFile
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
SteveDB1 SteveDB1 is offline
external usenet poster
 
Posts: 414
Default FSO.MoveFile

Simon,
Thank you for the clarification.
We don't place macros in our workbooks. We use everything from either our
xlsb, or xlam files.
Too many non-macro users modfiy these files, and with as tight as the
security is on 2007 now, we don't want to give them any reason to get
confused.

While we're in testing stages we only place the testing macros in the xlsb
files. After all of our testing is complete we disseminate them through our
xlam files.

"Simon Murphy" wrote:

Steve
You can't move an open file via Windows Explorer, so I doubt you can
with FSO.
is the .xlsx the right extension? it should be xlsm if it has macros.

Cheers
Simon
Blog: www.smurfonspreadsheets.net


SteveDB1 wrote:
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.