我修改的代码,我用来调用多个工作表,&我想用它来调用网址。为什么我在使用select case语句时遇到其他错误,我该如何解决?
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
我得到一个编译错误:否则与出如果。错误发生在以下提示处:案例1 '下面的消息仅在您处于活动工作表时显示。 MsgBox“你已经在OVR办公室目录!”,vbInformation,“推荐工作簿 - 数据输入” 其他其他。是否有可能做我想做的事,我错过了什么。我确实有一个选择案例我的值,它似乎是不够或在错误的位置。请告诉我我做错了什么。
从修复缩进开始。我尝试用[Rubberduck的智能压痕](http://rubberduckvba.com/Indentation)对它进行缩进,但即使用'Case Else'替换了'Else',你会注意到之前有一个'End If' “当条件=值2”时执行的代码注释,然后压头与所有这些不匹配的块完全混淆。 'If ... Else ... End If','Select Case ... Case ... Else ... End Select' - 不要混合匹配,编译器不喜欢它。 –
我试着修复你的代码,但老实说...这是相当混乱。你在'Select Case'块外面有'Case 2',我认为它属于下面,但是它在'[Case] Else'之后,并且'Case 2'下还有另一个'[Case] Else',我没有想法,你实际上打算运行每个'ie.Navigate'调用的条件。我认为你需要退后一步,写下你的意思,*然后*实施它,......使用合法的,*一致的*结构。 –