Vba 为什么在使用select case语句时会出现else错误&;我怎么修理它?

Vba 为什么在使用select case语句时会出现else错误&;我怎么修理它?,vba,excel,Vba,Excel,我修改了用于调用多个工作表的代码&我想用它来调用web地址 Sub OVR_Office_Listing() Dim i As String 'MsgBox prompt:="1st 6 Months of Reports?", Title:="Referral Workbook - Data Entry" i = MsgBox("Continue to OVR Office Directory?", vbYesNo, " Referral Workbook - Data Entry")

我修改了用于调用多个工作表的代码&我想用它来调用web地址

Sub OVR_Office_Listing()
  Dim i As String

'MsgBox prompt:="1st 6 Months of Reports?", Title:="Referral Workbook - Data Entry"
i = MsgBox("Continue to OVR Office Directory?", vbYesNo, " Referral Workbook - Data Entry")

If Not i = vbYes Then Exit Sub

'First message shows in the body of the box, message 2 shows at the top of the box.
Do
    MyValue = Application.InputBox("Only Click Ok or Cancel after your Selection!!!!!!!" & vbCrLf & _
                           "1 = OVR Office Directory" & vbCrLf & _
                           "2 = BBVS (Bureau of Blindness & Visual Services)Office Directory", "Walk In Training Data Entry")
    ' Sub messaage box exit.
    If MyValue = False Then
        Exit Sub
    ElseIf (MyValue = 1) Or (MyValue = 2) Then
        Exit Do
    Else
        MsgBox "You have not made a valid entry.  Please try again.", vbInformation, "Referral Workbook - Data Entry"
    End If
Loop    'Code to Execute When Condition = value_1

Select Case MyValue
    Case 1
           ' The message below only shows when you are on the active sheet.
                    MsgBox "You are already on OVR Office Directory!", vbInformation, "Referral Workbook - Data Entry"
                Else
                Dim ie As Object
Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
ie.NAVIGATE "http://www.dli.pa.gov/Individuals/Disability-Services/bbvs/Pages/BBVS-Office-Directory.aspx"
ie.Visible = True
End Select
                End If
    'Code to Execute When Condition = value_2
    Case 2

           ' The message below only shows when you are on the active sheet.
                    MsgBox "You are already on Bureau of Blindness & Visual Services Office Directory!", vbInformation, "Referral Workbook - Data Entry"
                Else
                  Dim ie As Object
Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
ie.NAVIGATE "http://www.dli.pa.gov/individuals/disability-services/ovr/pages/OVR-office-directory.aspx"
ie.Visible = True
End Select

                End If
End Select
End Sub
我得到一个编译错误:Else不带if。错误发生在以下情况:情况1 '下面的消息仅在您在活动工作表上时显示。 MsgBox“您已经在OVR Office目录中!”,vbInformation,“转诊工作簿-数据输入”
Else
在Else上。有没有可能做我正在尝试的事情,我错过了什么。我确实有一个选择案例MyValue,但它似乎不够或位于错误的位置。请告诉我我做错了什么。

Else
更改为
Case Else
Else
本身需要一个匹配的
If
语句。

尝试使用下面的代码

Sub OVR_Office_Listing()
  Dim i As String

'MsgBox prompt:="1st 6 Months of Reports?", Title:="Referral Workbook - Data Entry"
i = MsgBox("Continue to OVR Office Directory?", vbYesNo, " Referral Workbook - Data Entry")

If Not i = vbYes Then Exit Sub

'First message shows in the body of the box, message 2 shows at the top of the box.
Do
    MyValue = Application.InputBox("Only Click Ok or Cancel after your Selection!!!!!!!" & vbCrLf & _
                           "1 = OVR Office Directory" & vbCrLf & _
                           "2 = BBVS (Bureau of Blindness & Visual Services)Office Directory", "Walk In Training Data Entry")
    ' Sub messaage box exit.
    If MyValue = False Then
        Exit Sub
    ElseIf (MyValue = 1) Or (MyValue = 2) Then
        Exit Do
    Else
        MsgBox "You have not made a valid entry.  Please try again.", vbInformation, "Referral Workbook - Data Entry"
    End If
Loop    'Code to Execute When Condition = value_1

Select Case MyValue
    Case 1
           ' The message below only shows when you are on the active sheet.
                    MsgBox "You are already on OVR Office Directory!", vbInformation, "Referral Workbook - Data Entry"
    Case 2
                Dim ie As Object
Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
ie.NAVIGATE "http://www.dli.pa.gov/Individuals/Disability-Services/bbvs/Pages/BBVS-Office-Directory.aspx"
ie.Visible = True
'End Select
                'End If
    'Code to Execute When Condition = value_2
    Case 3

           ' The message below only shows when you are on the active sheet.
                    MsgBox "You are already on Bureau of Blindness & Visual Services Office Directory!", vbInformation, "Referral Workbook - Data Entry"
                'Else
                  Dim ie2 As Object
Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
ie2.NAVIGATE "http://www.dli.pa.gov/individuals/disability-services/ovr/pages/OVR-office-directory.aspx"
ie2.Visible = True
End Select
问题解决了

      `Sub OVR_Office_Listing()
      Dim i As String
     'MsgBox prompt:="1st 6 Months of Reports?", Title:="Referral Workbook - Data  Entry"
     i = MsgBox("Continue to OVR Directories?", vbYesNo, " Referral Workbook - Data Entry")

   If Not i = vbYes Then Exit Sub

   'First message shows in the body of the box, message 2 shows at the top of the box.

   Do
   MyValue = Application.InputBox("Only Click Ok or Cancel after your  Selection!!!!!!!" & vbCrLf & _
                       "1 = OVR Office Directory" & vbCrLf & _
                       "2 = BBVS (Bureau of Blindness & Visual Services)    Office Directory", "Walk In Training Data Entry")
 'Sub messaage box exit.
 If MyValue = False Then
    Exit Sub
 ElseIf (MyValue = 1) Or (MyValue = 2) Then
    Exit Do
 Else
 MsgBox "You have not made a valid entry.  Please try again.",  vbInformation, "Referral Workbook - Data Entry"
 End If

 Loop
'Code to Execute When Condition = value_1
Select Case MyValue
Case 1
'Message prior to calling the webb address.
                MsgBox "Please wait, while get you the OVR web address.", vbInformation, "Referral Workbook - Data Entry"

            Dim ie As Object
Set ie1 = CreateObject("INTERNETEXPLORER.APPLICATION")
ie1.NAVIGATE "http://www.dli.pa.gov/individuals/disability- services/ovr/pages/OVR-office-directory.aspx"
ie1.Visible = True
 'Code to Execute When Condition = value_2
Select Case MyValue
 End Select
 Case 2

       'Message prior to calling the webb address.
                MsgBox "Please wait, while I get you the Bureau of Blindness & Visual Services Office Directory!", vbInformation, "Referral Workbook - Data Entry"
            'Else
              Dim ie2 As Object
  Set ie2 = CreateObject("INTERNETEXPLORER.APPLICATION")
  ie2.NAVIGATE "http://www.dli.pa.gov/Individuals/Disability-Services/bbvs/Pages/BBVS-Office-Directory.aspx"
  ie2.Visible = True
  End Select
 End Sub`

从固定压痕开始。我试着用缩进,但即使用
Case Else
替换
Else
,您也会注意到在条件=值_2注释时要执行的
代码之前有一个错误的
End if
,然后缩进器会与所有这些不匹配的块完全混淆
If…Else…End If
选择Case…Case…Case Else…End Select
-不要混搭,编译器不喜欢它。我试着修复你的代码,但老实说。。。真是一团糟。你有
case2
Select Case
块之外,我想它应该在下面,但是它在
[Case]Else
之后,在
case2
下还有另一个
[Case]Else
,我不知道你实际上打算在什么条件下运行每个
即导航
调用。我认为你需要后退一步,写下你想做什么,然后实现它,…使用合法、一致的构造。选择代码,按Ctrl+K…好的,为你做了。您缺少
结束子按钮
。我误按了回车键。这是修改后的代码,我让它运行,但它运行到IE2<代码>尺寸ie2作为对象集ie2=CreateObject(“INTERNETEXPLORER.APPLICATION”)ie2.NAVIGATE“http://www.dli.pa.gov/individuals/disability-services/ovr/pages/OVR-office-directory.aspx“ie2.Visible=True End Select
如果我选择1,它将不显示任何活动。只需将ELSE语句更改为CASE ELSE,仍然不会编译。他试图在两个CASE语句中使用块IF,而不使用IF。需要很多mod来编译这个,你能解释一下你说“需要很多mod来编译这个”的意思吗@卡西里耶!很高兴你成功了,伙计