Consulting

Results 1 to 7 of 7

Thread: VBA code runs when workbook is closed?

  1. #1

    Question VBA code runs when workbook is closed?

    I am looking to see if there is a way to run a marco/sub at a 11pm in the evening. I have created a new workbook with the following code.....what i want to do is for it to make a copy of anohter workbook - saving it in a pre determined folder. But i dont want any user interaction. Can the code do all of this itself?

    [vba]

    Sub Backup()
    Fname = NewStarterTracker.Name
    Workbook("TestGood5").SaveCopyAs "\\ukyorw09\HR\IAC New Starter Tracking\IAC\Application\Backup\ & Fname"
    ActiveWorkbook.Save
    ActiveWorkbook.Close

    End Sub

    [/vba]

    I need to know how to nominate which workbook to backup. My current code Workbook(Itsname).SaveCopyAs doesnt work....do i need to put its path in somehow? Can ne1 help?

  2. #2
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    273
    Location
    [VBA]Workbook("TestGood5").SaveCopyAs "\\ukyorw09\HR\IAC New Starter Tracking\IAC\Application\Backup\" & Fname [/VBA]

  3. #3
    Isnt that what i aleady have, whats the difference?

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    If Excel is running at 11PM and OnTime has been used to set the macro "BackUp" to run at 11PM, the workbook containing "BackUp" will be opened and BackUp run automaticaly at 11PM.

  5. #5
    Right, excel wont be open you see. Therefore what happens if i used Windows task scheduler to open it? But each users machine will be turned off at night?

  6. #6
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    273
    Location
    i moved the " so that you have a string + the file name befor you have one string

    your code always tryed to save to "\\ukyorw09\HR\IAC New Starter Tracking\IAC\Application\Backup\ & Fname" which probibly failed because you have a & in the file name

    mine saves to "\\ukyorw09\HR\IAC New Starter Tracking\IAC\Application\Backup\" plus Fname

    now it still might fail, for i am not sure what NewStarterTracker.Name generates as a name

  7. #7
    It orginally said "ThisWorkbook.Name" So i assumed i could replace this and call the backup what i want?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •