Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-03-2012, 04:18 AM
tinfanide tinfanide is offline Why run-time is always different from stepping into the codes? Windows 7 64bit Why run-time is always different from stepping into the codes? Office 2010 32bit
Expert
Why run-time is always different from stepping into the codes?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default Why run-time is always different from stepping into the codes?


Just recently I've posted the same file in this forum and now I've got another example that

the run-time result is just different from what I can get when I step into the codes pressing F8 every time. It drives me crazy cos it wastes all of my time (a few hours) to make sure the codes run well before run-time. When I press F5 to run it all, it just differs and I am totally frustrated here.

Please help take a look at the file (see the comments in the codes for the problem) and if you can walk me through this problem, I would be very thankful for your help. It does help me understand VBA far better.

Many thanks in advance.
Attached Files
File Type: xlsm Application Data - Copy.xlsm (28.6 KB, 9 views)
Reply With Quote
  #2  
Old 03-04-2012, 12:04 AM
tinfanide tinfanide is offline Why run-time is always different from stepping into the codes? Windows 7 64bit Why run-time is always different from stepping into the codes? Office 2010 32bit
Expert
Why run-time is always different from stepping into the codes?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Self solved.

Code:
Sub test()
Application.ScreenUpdating = False

ThisWorkbook.Activate
Worksheets("ApplicationData").Select

Dim IE As Object
Dim HTMLDoc As Object
Dim oRange As Range
Dim pos As Long

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False

For Each cell In Selection.Cells

    IE.Navigate "http://www.chsc.hk/ssp/main.php?lang_id=1"
    While IE.readyState < 4
    Application.Wait DateAdd("s", 1 / 1000, Now)
    Wend
    Set HTMLDoc = IE.Document
    
    
    HTMLDoc.getElementById("sch_name").Value = Cells(cell.Row, 2).Value
    HTMLDoc.getElementById("btn_search").Click
    
                            
    Application.Wait DateAdd("s", 1, Now)
                            
                            
    For Each tr In HTMLDoc.getElementsByTagName("tr")
        If tr.className = "psp_table_line2_bgcolor" Then
            IE.Navigate tr.getElementsByTagName("a")(0).href
            Exit For
        End If
    Next
    
    Application.Wait DateAdd("s", 1, Now)
    
    Cells(cell.Row, 3).Value = HTMLDoc.getElementsByTagName("span")(3).innerText
    Cells(cell.Row, 4).Value = HTMLDoc.getElementsByTagName("td")(73).innerText

    Set oRange = Cells(cell.Row, 4).Find(What:="(", LookAt:=xlPart)
        
    If Not oRange Is Nothing Then
        pos = Application.WorksheetFunction.Find("(", Cells(cell.Row, 4).Value) - 1
        Cells(cell.Row, 4) = Trim(Left(Cells(cell.Row, 4).Value, pos))
    End If


Next cell


IE.Quit
Set IE = Nothing
Application.ScreenUpdating = True

End Sub
With the use of
Code:
 Application.Wait DateAdd("s", 1, Now)
Excel seems to have gone to the right page expected.
I don't know why waiting for the least of ONE second will get Excel extract data from the page designated.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why run-time is always different from stepping into the codes? Word Equation field codes mkarthic Word 1 12-02-2011 02:09 AM
Why run-time is always different from stepping into the codes? Mail merge erases field codes Medievalguy88 Mail Merge 1 08-11-2011 05:21 AM
Convert LISTNUM field codes to text remedios43 Word 2 07-31-2011 09:21 AM
Why run-time is always different from stepping into the codes? confusion with merge and field codes BluRay Mail Merge 5 03-29-2011 01:06 AM
Why run-time is always different from stepping into the codes? Using Field Codes to Calculate 5 years from a Date vandy Word 1 09-23-2009 11:32 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:53 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft