Results 1 to 2 of 2

Timer , code to check IF worksheet is open else Close it. ??

Threaded View

  1. #1
    Registered User
    Join Date
    11-05-2012
    Location
    Zutphen
    MS-Off Ver
    Excel 2003
    Posts
    56

    Timer , code to check IF worksheet is open else Close it. ??

    Hello,

    On my userform i have an OK button and a Refresh userform button , and an Userform initialize.
    When somebody has entered all the data they press the OK button and it all the data enters on a worksheet. Then it closes.
    Because of this..
    ActiveWorksheet.Close True
    I also have a timer which closes it if there is no activity.
    Private Sub UserForm_Activate()
    startTimer = Timer
    Do While Timer < (startTimer + 15)
    DoEvents
    Loop
    MsgBox " Je bent 15 seconden inactief geweeest, de file sluit nu."
    ActiveWorkbook.Close True
    Application.ScreenUpdating = True
    And i have a Update refresh button.
    Unload Me
    UserForm1 Show
    And last but not least , on initialize it opens the file again.
    set wb = Workbooks.Open("Z:\VBA gekloot\Userform\Voortgangproduktiestart.xls")
    The problem: Many times because of the timer or OK button it tries to close the file while there is no file open which gives an ERROR.
    Or the person presses Update/refresh before the file is closed and then the userform initializes and tries to open the file again which causes the error , or popup : This file already open are you sure blablalbla.

    Solution : A way to check if workbook is open else close it. I tried: If WorkbookIsOpen then Workbook(name.xls).close true
    but cannot figure out how to do it.
    Last edited by stevnb; 12-07-2012 at 06:43 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1