Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel vba for Internet explorer-当为月份选择的下拉列表为空时如何显示错误消息框_Excel_Vba - Fatal编程技术网

Excel vba for Internet explorer-当为月份选择的下拉列表为空时如何显示错误消息框

Excel vba for Internet explorer-当为月份选择的下拉列表为空时如何显示错误消息框,excel,vba,Excel,Vba,这是我的密码。我已经在需要检查空下拉列表的地方添加了一些备注 Dim IE As Object Application.DisplayAlerts = False Dim chromePath As String Set IE = CreateObject("InternetExplorer.application") IE.Navigate "https://www.facebook.com/" IE.Visible = True Dim doc

这是我的密码。我已经在需要检查空下拉列表的地方添加了一些备注


Dim IE As Object Application.DisplayAlerts = False
Dim chromePath As String

     Set IE = CreateObject("InternetExplorer.application")
     IE.Navigate "https://www.facebook.com/"      
     IE.Visible = True

Dim doc As Object

     IE.Top = 0
     IE.Left = 0
     IE.Width = 1200
     IE.Height = 1000
     IE.AddressBar = 0
     IE.StatusBar = 0
     IE.Toolbar = 0
     IE.Visible = True
     With IE
          Do
               If IE.ReadyState = 4 Then
                    IE.Visible = True
                    Exit Do
               Else
                    DoEvents
               End If
          Loop
          DoEvents
          Application.Wait Now + TimeValue("00:00:05")
          IE.Document.getElementById("month").selectedIndex = -2
          '(Here i want to check if the selected dropdown is blank as in case
          'of month on facebook I want to show some error and also want to do
          'some more action) 'On Error GoTo Prob MsgBox "Code has completed"
          'Exit Sub
          'Prob: MsgBox Err.Description & " has prevented the code completing"
     End With

在这里,如果我选择0,它给我“月”,但如果我选择一个值超出范围,请考虑它作为- 2(任何值超出范围从下拉列表)比你将获得“空框”代替“月份”。所以现在我可能有任何值,比如-2或-3或-4,15,18,19等等,我将得到同样的“空框”,这需要处理,最后在这个例子中,我们只处理整数,但我希望对字符串进行相同的比较,因为有许多字符串。因此,如果选择的“空框”有任何部分的空值,这肯定会起作用,但我不知道“空框”的值是多少,所以我无法继续,所以请你help@user2485794我不确定我是否理解你。。。我在“getElementById”调用中添加了“.value”,这意味着它显示了下拉列表的值。这是你的问题。。。“我想检查所选下拉列表是否为空”(在FB示例中,“月”表示为空/留空)如果我把您弄糊涂了,很抱歉……实际上我将使用类似于此范围(“D1”)的内容。选择名称=activeCell.Value IE.Document.getElementById(“日”)。值=名称如果(IE.Document.getElementById(“日”)).Value=Name)然后“调用MsgBox(“消息框”)MsgBox(“已工作”)否则MsgBox(“未工作”)结束如果在此情况下,我将从excel中获取一些值,如果所选下拉列表与给定下拉列表匹配,则会尝试选择下拉列表,而不是显示已工作或未工作,

If (IE.Document.getElementById("month").value = 0) Then
'or null, Empty, etc depending on element type (for combo it's 0th item)
     Call MsgBox ("The message box")
     'the other things you want to do
End If