• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Saving copy of autorecovery files

Cammandk

Member
Is it possible to write some VBA code that before I save my workbook it takes a copy of all the autorecovery files that may have been created in Path A: and copies them to Path B:
 
Hi, Cammandk!


The path where Excel stores the autorecovery files is held in this property:

Application.AutoRecover.Path


So theoretically at least you have many different ways for copying files (in fact folders) from that folder to any other folder. For doing that before saving a file you should place this code structure in the class module of ThisWorkbook:

-----

[pre]
Code:
Option Explicit

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Const ksTargetPath = "any target"
DoSomething
End Sub
[/pre]
-----


Where in the DoSomething procedure you have to put the code for doing the job. But before entering in that code, maybe you want to elaborate a bit more and explain your requirement since I don't understand what do you want to achieve.


Despite of this, there're many methods for copying files/folders:

- recursive loops issuing DIR instruction

- using file system object methods

- executing shell commands

and maybe I forget others.


Before digging deeper into how to do the copy, it'd be advisable if you tell us what are you going to do with those copied files.


Regards!
 
Back
Top