2017-10-20 60 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

相关问题