VBA: Else without If Error

J'essaie d'exécuter le code suivant, mais je continue d'get l'erreur Else sans If dans le premier sous. Le code est censé fonctionner dans une colonne, ouvrir les pages Web s'il existe une URL dans la cellule, puis save les informations de la page en tant que file text. S'il n'y a pas d'url, il enregistre simplement le text dans ce file en tant que file text. Je ne peux pas comprendre comment modifier la syntaxe pour qu'elle fonctionne.

Sub LoopOverB() Dim myRow As Long myRow = 10 While Worksheets("Input_Format_A").Cells(myRow, 2).value <> "" If InStr(1, Worksheets("Input_Format_A").Cells(myRow, 2).value, "http://", vbTextCompare) Then Call url_Test(Worksheets("Input_Format_A").Cells(myRow, 2).value, "C:\mallet\test\" & Worksheets("Input_Format_A").Cells(myRow, 1).value & ".txt") myRow = myRow + 1 Else Open "C:\mallet\test\" & Worksheets("Input_Format_A").Cells(myRow, 1) & ".txt" For Append As #1 Print #1, Worksheets("Input_Format_A").Cells(myRow, 2).value Close #1 myRow = myRow + 1 End If Wend End Sub Sub url_Test(URL As Ssortingng, Filename As Ssortingng) Dim FSO As Object Dim ieApp As Object Dim Txt As Ssortingng Dim TxtFile As Object Set FSO = CreateObject("Scripting.FileSystemObject") Set TxtFile = FSO.OpenTextFile(Filename, 2, True, -1) Set ieApp = CreateObject("InternetExplorer.Application") ieApp.Visible = True ieApp.Navigate URL While ieApp.Busy Or ieApp.ReadyState <> 4 DoEvents Wend Txt = ieApp.Document.body.innerText TxtFile.Write Txt TxtFile.Close ieApp.Quit Set ieApp = Nothing Set FSO = Nothing End Sub 

Sur la ligne avec le premier If , vous devez passer à une nouvelle ligne après Then , sinon votre If sera implicitement fermé.

 'Good (in this case) If <condition> Then DoSomething myRow = myRow + 1 Else DoSomething Different End if 'NOT good If <condition> Then DoSomething 'the if is now "closed" !!! myRow = myRow + 1 Else DoSomething Different End if «Bon (dans ce cas) 'Good (in this case) If <condition> Then DoSomething myRow = myRow + 1 Else DoSomething Different End if 'NOT good If <condition> Then DoSomething 'the if is now "closed" !!! myRow = myRow + 1 Else DoSomething Different End if Si <condition> Ensuite 'Good (in this case) If <condition> Then DoSomething myRow = myRow + 1 Else DoSomething Different End if 'NOT good If <condition> Then DoSomething 'the if is now "closed" !!! myRow = myRow + 1 Else DoSomething Different End if myRow = myRow + 1 'Good (in this case) If <condition> Then DoSomething myRow = myRow + 1 Else DoSomething Different End if 'NOT good If <condition> Then DoSomething 'the if is now "closed" !!! myRow = myRow + 1 Else DoSomething Different End if Si <condition> Ensuite DoSomething 'Good (in this case) If <condition> Then DoSomething myRow = myRow + 1 Else DoSomething Different End if 'NOT good If <condition> Then DoSomething 'the if is now "closed" !!! myRow = myRow + 1 Else DoSomething Different End if 'the if is now "closed" !!! 'Good (in this case) If <condition> Then DoSomething myRow = myRow + 1 Else DoSomething Different End if 'NOT good If <condition> Then DoSomething 'the if is now "closed" !!! myRow = myRow + 1 Else DoSomething Different End if myRow = myRow + 1 'Good (in this case) If <condition> Then DoSomething myRow = myRow + 1 Else DoSomething Different End if 'NOT good If <condition> Then DoSomething 'the if is now "closed" !!! myRow = myRow + 1 Else DoSomething Different End if