发生在这个片断的问题:
Private Sub UserForm_Activate()
Application.Wait (Now + TimeValue("00:00:01"))
UserForm1.Label1.Caption = "Loading Data..."
UserForm1.Repaint
Application.Wait (Now + TimeValue("00:00:03"))
UserForm1.Label1.Caption = "Please make sure Database file is open..."
UserForm1.Repaint
Application.Wait (Now + TimeValue("00:00:02"))
UserForm1.Label1.Caption = "Opening..."
UserForm1.Repaint
Application.Wait (Now + TimeValue("00:00:01"))
Unload UserForm1
End Sub
的应用只是等待(所以不接受任何输入)。这就是为什么你的事件不会触发的原因,因为在等待之后它会立即继续下一行(这是标签更改和重绘)。
您可以通过如下改变这个例程修复:
Private Sub UserForm_Activate()
Application.Wait (Now + TimeValue("00:00:01"))
DoEvents 'Allow for the label click to trigger!!!
UserForm1.Label1.Caption = "Loading Data..."
UserForm1.Repaint
Application.Wait (Now + TimeValue("00:00:03"))
DoEvents 'Allow for the label click to trigger!!!
UserForm1.Label1.Caption = "Please make sure Database file is open..."
UserForm1.Repaint
Application.Wait (Now + TimeValue("00:00:02"))
DoEvents 'Allow for the label click to trigger!!!
UserForm1.Label1.Caption = "Opening..."
UserForm1.Repaint
Application.Wait (Now + TimeValue("00:00:01"))
DoEvents 'Allow for the label click to trigger!!!
Unload UserForm1
End Sub
这不是很干净,但这样一来,你就没有其他改变输入事件代码,并解决您的问题。
编辑: 这个答案告诉你如何捕捉事件并使其工作,这就是问题所在。 FollowHyperlink
的问题是第二件事:MSDN表示该方法将根据您传递的目标“打开适当的程序”。
由于代码是正确的和的事件触发,这是最有可能是完全不同的问题有什么做的VBA /你的问题。
在我的机器上(W7 + Excel 2016),代码执行完美,点击链接一直工作。
究竟什么不行? 这里罚款。 –
超链接无法正常工作。每当我点击超链接,网站都没有打开。 – omprakash
您是否尝试过使用F8执行,以查看上述事件是否被解雇?您是否收到MsgBox说“无法打开https ......”? –