我修改的代碼,我用來調用多個工作表,&我想用它來調用網址。爲什麼我在使用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'調用的條件。我認爲你需要退後一步,寫下你的意思,*然後*實施它,......使用合法的,*一致的*結構。 –