Results 1 to 2 of 2

Thread: Code Hangs (03)

  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    California, USA
    Thanked 0 Times in 0 Posts

    Code Hangs (03)

    I have two Excel files the first is a record log of the job being run ie this particular file is scheduled to be open by Window's Task Scheduler; timestamps two cells for the start/end of the job being run and then opens the second Excel file which runs code upon opening. Everything is fine with the code as I can run it just perfectly via Terminal Services

    My issue is that it occassionally hangs when the service is scheduled to run the Task Scheduler. The first file is opened and somewhere along the way it hangs up. Is there a way to capture the point where it may be hanging up? I know it is not a scheduled task issue as it does kick off.

    Your thoughts are appreciated,

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Code Hangs (03)

    You could write a line to a text file at critical points or even after each instruction. Copy the following procedure into a module in the problem workbook:

    Sub WriteLog(strText As String)
    Const strFile = "C:Log.txt"
    Dim f As Integer
    f = FreeFile
    Open strFile For Output As #f
    Print #f, strText
    Close #f
    End Sub

    Call WriteLog with a descriptive text in the code that runs on opening, for example

    Private Sub Workbook_Open()
    Call WriteLog("Enter time in cell A1")
    Range("A1") = Now
    Call WriteLog("Open other workbook")
    Workbooks.Open "...."
    Call WriteLog("Do something else")
    End Sub

Posting Permissions

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