2017-10-20 17 views
0

J'ai modifié le code que j'utilise pour appeler plusieurs feuilles de calcul, & Je voudrais l'utiliser pour appeler des adresses Web.Pourquoi est-ce que je reçois une autre erreur lorsque j'utilise une instruction case select et comment la corriger?

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 

Je reçois une erreur de compilation: Sinon avec si. L'erreur se produit à la lication suivante: Cas 1 'Le message ci-dessous ne s'affiche que lorsque vous êtes sur la feuille active. MsgBox "Vous êtes déjà dans le répertoire Office OVR!", VbInformation, "Manuel de référence - Entrée de données" Sinon Sinon. Est-il possible de faire ce que je tente, et qu'est-ce qui me manque? J'ai un Select Case MyValue, et il semble que ce n'est pas assez ou au mauvais endroit. S'il vous plaît dites-moi ce que je fais mal.

+0

Commencez par fixer l'indentation. J'ai essayé de le mettre en retrait avec [Smart Indenter de Rubberduck] (http://rubberduckvba.com/Indentation), mais même si vous remplacez ce 'Else' par' Case Else', vous remarquerez qu'il y a un 'End If' égaré avant le commentaire "Code à exécuter lorsque condition = valeur_2", puis le pénétrateur est complètement confondu avec tous ces blocs incompatibles. 'Si ... Sinon ... Fin If ',' Select Case ... Case ... Case Sinon ... End Select' - ne mélange pas et ne correspond pas, le compilateur ne l'aime pas. –

+1

J'ai essayé de corriger votre code, mais honnêtement ... c'est un gros gâchis. Vous avez 'Case 2' en dehors du bloc' Select Case' je pense qu'il appartient, mais après c'est '[Case] ​​Else', et il y a un autre' [Case] ​​Else' sous 'Case 2', IOW je n'ai pas idée sous quelle (s) condition (s) vous avez réellement l'intention de lancer chaque appel 'ie.Navigate'. Je pense que vous devez prendre du recul et écrire ce que vous voulez faire, * puis * le mettre en œuvre, ... en utilisant des constructions légales, * cohérentes *. –

Répondre

0

Remplacez Else par Case Else. Else requiert à lui seul une instruction If correspondante.

+0

La simple modification de l'instruction ELSE en CASE ELSE ne sera toujours pas compilée. Il essaie d'utiliser un bloc IF à l'intérieur des deux instructions CASE sans l'IF. De nombreux mods sont nécessaires pour compiler ceci – KacireeSoftware

+0

Pourriez-vous expliquer ce que vous voulez dire quand vous dites "De nombreux mods sont nécessaires pour compiler". @KacireeSoftware –

0

essayez d'utiliser le code ci-dessous.

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

Sélectionnez le code, appuyez sur Ctrl + K ... ok, l'a fait pour vous. Vous manquez le 'End Sub'. –

+0

Idid un peu d'édition –

+0

J'appuie sur la touche Entrée par erreur. Voici le code révisé –

1

Problèmes résolus.

 `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

Yay! Je suis content que vous l'ayez vu mon pote – KacireeSoftware