Results 1 to 6 of 6

Thread: Close file after 3 minutes?

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Close file after 3 minutes?

    Why doesn't this code work...

    VB Code:
    1. Public Sub Document_Open()
    2.  
    3. Application.OnTime DateAdd("n", 10, Now), SaveAndClose
    4.  
    5. End Sub
    6.  
    7. Private Function SaveAndClose()
    8.  
    9. Me.Close True
    10.  
    11. End Function

    It is supposed to close a file 10 minutes after it was opened, but instead the file closes instantly.

    Also, why is VBA so lame?
    Last edited by wossname; Sep 13th, 2004 at 08:48 AM.
    I don't live here any more.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Dunno if this is gonna work the way you want...
    An API call to send the application to sleep, for five secs...


    Vince
    Attached Files Attached Files

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    I need to be able to edit the file manually while it is still open.

    Any ideas why this OnTime thing doesn't work?
    I don't live here any more.

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Nope no idea sorry.

    Had a look on the MS site, but nothing useful there.

    Why would anyone want to delay their code after pressing a button to run something?? weird.

    I did shove a doevents in before the time setting code, but it still executed immediately.
    Possibly something that it depends on hasn't been set if its opened up and exppected to run.

    <kicks ms office> useless.


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  5. #5

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    I hate VBA.

    I need this because we have a file on the LAN that everyone must edit every now and then, but only 1 person can have it open at any time. So if someone opens it and forgets to close it then everyone else is buggered, hence the timeout.

    Seems like the function doesn't work or has become obsolete.
    I don't live here any more.

  6. #6
    Member
    Join Date
    Mar 2002
    Location
    Grimsby (up the Mariners!)
    Posts
    45

    It does work, we use it a lot

    In the OnTime method, put the name of the procedure in double quotes. Change the Function to a Sub and it should work (set to 5 secs for testing!).

    VB Code:
    1. Public Sub Document_Open()
    2.   Application.OnTime DateAdd("s", 5, Now), "SaveAndClose"
    3. End Sub
    4.  
    5. Sub SaveAndClose()
    6.   Me.Close True
    7. End Function

Posting Permissions

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



Click Here to Expand Forum to Full Width