1. You are viewing our forum as a guest. For full access please Register. WindowsBBS.com is completely free, paid for by advertisers and donations.

Run a task every minute

Discussion in 'Windows XP' started by clinet, 2012/03/08.

  1. 2012/03/08
    clinet

    clinet Inactive Thread Starter

    Joined:
    2011/04/29
    Messages:
    25
    Likes Received:
    0
    On my PC I have an Excel sheet that I have open all day for changes. I would like to copy every minute to another file on an external network hard drive so another person can see my latest changes. I currently have a scheduled DOS task that does this, but limited to once a day. The PC Task Schedular doesn't appear to have periods less than once a day either. Does any body have a suggestion?
     
  2. 2012/03/08
    Steve R Jones

    Steve R Jones SuperGeek Staff

    Joined:
    2001/12/30
    Messages:
    12,315
    Likes Received:
    252
    Have you considered just using the one networked file?
     

  3. to hide this advert.

  4. 2012/03/08
    PeteC

    PeteC SuperGeek Staff

    Joined:
    2002/05/10
    Messages:
    28,896
    Likes Received:
    389
    SynchBackSE will allow you to schedule every minute AFAIK - use it myself, but hourly.
     
  5. 2012/03/08
    dnmacleod

    dnmacleod Well-Known Member

    Joined:
    2009/05/16
    Messages:
    419
    Likes Received:
    58
    Haven't tested this but it should autosave at the desired interval and include a timestamp in the filename. Include it as a module in your open workbook.

    Public saveTime As Date

    Sub AutoSaveAs()
    saveTime = Time + TimeValue( "00:05:00 ") ' set this to whatever interval you want
    With Application
    .OnTime saveTime, "AutoSaveAs"
    .EnableEvents = False
    .DisplayAlerts = False
    ThisWorkbook.SaveAs "FilePath&NameHere" & saveTime & ".xlsx" ' make it xlsm if you want it to be a macro enabled file.
    .EnableEvents = True
    End With
    End Sub
     
  6. 2012/03/08
    clinet

    clinet Inactive Thread Starter

    Joined:
    2011/04/29
    Messages:
    25
    Likes Received:
    0
    Thanks dnmacleod.
    Before I load this I have questions...
    If I make it Public, when does it get initially launched?
    If I make it a macro, does it become manual?
    Does the timestamp at the end of the file name make it a unique file (not overlay)?
     
  7. 2012/03/08
    dnmacleod

    dnmacleod Well-Known Member

    Joined:
    2009/05/16
    Messages:
    419
    Likes Received:
    58
    OOPS :eek: :eek: :eek:

    That's what happens when you post code without checking it first....

    Re-write.....
    -----------------------------------------------------------

    Public saveTime As Date

    Sub AutoSaveAs()
    Dim dt As String
    dt = Format(CStr(Now), "mm_dd_hh_mm ") ' Edit the Date/Time format as you see fit
    saveTime = Time + TimeValue( "00:05:00 ") ' set this to whatever interval you want - in this case 5 mins
    With Application
    .OnTime saveTime, "AutoSaveAs "
    .EnableEvents = False
    .DisplayAlerts = False
    ActiveWorkbook.SaveAs "C:\Path\To\File\name_" & dt & ".xlsm"
    .EnableEvents = True
    End With
    End Sub

    If you want to auto run the macro on opening the workbook, place a call to AutoSaveAs in ThisWorkbook under WorkBook Open thus:

    Private Sub Workbook_Open()

    Call AutoSaveAs

    End Sub

    If you want to manually run the macro initially, don't include the Call.

    The timestamp will save it as a new unique file every time.

    Also, the macro will continue to run after the workbook has been closed until Excel is fully closed down. When Excel is restarted, the macro will not restart until the workbook is re-opened.
     
    Last edited: 2012/03/08
  8. 2012/03/09
    dnmacleod

    dnmacleod Well-Known Member

    Joined:
    2009/05/16
    Messages:
    419
    Likes Received:
    58
    Add the following sub underneath the auto start call in the ThisWorkbook module to stop the macro when you close the workbook.

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.OnTime saveTime, "AutoSaveAs ", Schedule:=False
    End Sub
     
  9. 2012/03/09
    clinet

    clinet Inactive Thread Starter

    Joined:
    2011/04/29
    Messages:
    25
    Likes Received:
    0
    dnmacleod,
    This method has more hoops to jump through than I feel necessary for my needs, so I think for business purposes I'll try some other basic system tools for now.
    Please understand that I greatly appreciate your contribution and will experiment with it in a non-business environment. If I get it working I may decide to use it in a number of applications.

    clinet
     
  10. 2012/03/09
    dnmacleod

    dnmacleod Well-Known Member

    Joined:
    2009/05/16
    Messages:
    419
    Likes Received:
    58
    Thats ok. Just one thing - I thought you wanted it saved as a unique file every time, thats why I included the timestamp. If you simply want to overwrite the remote file every time, simply change the line:

    ActiveWorkbook.SaveAs "C:\Path\To\File\name_" & dt & ".xlsm" to
    ActiveWorkbook.SaveAs "C:\Path\To\File\name.xlsm "
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.