假設你webbrower是[WB]
private sub subOpenHtml(byval sHtml as string)
WB.Navigate "about:blank" 'creates a document to do something on
subBrowserStopClickSound 'stops ie click sound '(not necessary but a nice touch so users of your program don't know you are hijacking IE.
setdocretry:
If WB.ReadyState = READYSTATE_COMPLETE Then
If Not (WB.Document Is Nothing) Then
WB.Document.open
WB.Document.write sHtml
WB.Document.Close
Else
Stop'error handling
End If
Else
Pause.subFor 1
GoTo setdocretry:
End If
end sub
代碼subBrowserStopClickSound(單獨的模塊好主意):
在模塊的頂部:
Private Declare Function CoInternetSetFeatureEnabled Lib "urlmon.dll" (ByVal FeatureEntry As Integer, ByVal dwFlags As Long, ByVal fEnable As Long) As Long
Private Const FEATURE_DISABLE_NAVIGATION_SOUNDS = 21
Private Const SET_FEATURE_ON_PROCESS As Integer = &H2
下面說:
private sub subBrowserStopClickSound
Call CoInternetSetFeatureEnabled(FEATURE_DISABLE_NAVIGATION_SOUNDS, SET_FEATURE_ON_PROCESS, True)
end sub
用於暫停的代碼:
再次地,在一個獨立的模塊(我發現這個代碼是在很多情況下是非常有用的,並且是的DoEvents更好和更可控的替代)
頂模塊的:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Type variables
loldSecond As Long
End Type
Dim v As variables
下面說:
Sub subFor(ByVal Delay As Single)
Dim seconds As Long
v.loldSecond = 0
Delay = (Timer + Delay)
Do
DoEvents: DoEvents: DoEvents: DoEvents
'tells us how many seconds left without decimal
seconds = (Delay - Timer)
Sleep 10
Loop While Delay > Timer
End Sub
很抱歉,如果我忽略的代碼的東西,如果是的話,請讓我知道這樣我就可以糾正。
一個小問題是你使用不屬於那裏的「愚蠢的括號」。雖然在這種情況下,除了讓事情運行速度慢一點(他們基本上說「評估這個並以價值傳遞結果」),它們不會傷害任何東西,在某些情況下可能導致各種悲傷。甚至IDE都會警告你(通過在左括號之前插入該空格)。 – Bob77