2017-10-20 27 views
0

我修改的代碼,我用來調用多個工作表,&我想用它來調用網址。爲什麼我在使用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,「推薦工作簿 - 數據輸入」 其他其他。是否有可能做我想做的事,我錯過了什麼。我確實有一個選擇案例我的值,它似乎是不夠或在錯誤的位置。請告訴我我做錯了什麼。

+0

從修復縮進開始。我嘗試用[Rubberduck的智能壓痕](http://rubberduckvba.com/Indentation)對它進行縮進,但即使用'Case Else'替換了'Else',你會注意到之前有一個'End If' 「當條件=值2」時執行的代碼註釋,然後壓頭與所有這些不匹配的塊完全混淆。 'If​​ ... Else ... End If','Select Case ... Case ... Else ... End Select' - 不要混合匹配,編譯器不喜歡它。 –

+1

我試着修復你的代碼,但老實說...這是相當混亂。你在'Select Case'塊外面有'Case 2',我認爲它屬於下面,但是它在'[Case] Else'之後,並且'Case 2'下還有另一個'[Case] Else',我沒有想法,你實際上打算運行每個'ie.Navigate'調用的條件。我認爲你需要退後一步,寫下你的意思,*然後*實施它,......使用合法的,*一致的*結構。 –

回答

0

Else更改爲Case ElseElse本身需要匹配If聲明。

+0

只需將ELSE語句更改爲CASE ELSE即可編譯。他試圖在沒有IF的CASE語句中使用塊IF。需要很多mod才能編譯 – KacireeSoftware

+0

你能否解釋一下當你說「需要多個mod來編譯」時你的意思。 @KacireeSoftware –

0

嘗試使用下面的代碼。

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 
+0

選擇代碼,按Ctrl + K ...好吧,爲你做好了。你錯過了'End Sub'。 –

+0

Idid一些編輯 –

+0

我錯誤地敲了回車鍵。這裏是修改後的代碼 –

1

問題已解決。

 `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` 
+0

耶!很高興你有它去那裏的朋友 – KacireeSoftware

相關問題