IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Run Time Error - 62 (Input Past End of File)


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Manager transformation digitale
    Inscrit en
    Mars 2020
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Manager transformation digitale

    Informations forums :
    Inscription : Mars 2020
    Messages : 1
    Par défaut Run Time Error - 62 (Input Past End of File)
    Bonjour à tous,
    J'ai ce code VBA que j'ai écris pour extraire des données dans un fichier HTML et le ranger dans une feuille excel.
    Le code marche parfaitement en France, mais quand une personnne se trouvant en Chine l'utilise ça afficher 'Run Time Error - 62 (Input Past End of File)'.
    Si vous pouvez m'aider svp.
    Merci.
    Rudy

    Le code est le suivant:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    Private Sub cmd_extract_Click()
     
    uf.Hide
     
    Dim html As Object
    Dim Tr As Object
    Dim Td As Object
    Dim Tab1 As Object
    Dim file As String
    Dim sh As Worksheet
     
    file = txt
     
    TextFile = FreeFile
     
    Open file For Input As TextFile
     
    Set HTML_Content = CreateObject("htmlfile")
     
    HTML_Content.body.innerHtml = Input(LOF(TextFile), TextFile)
     
    Column_Num_To_Start = 1
    iRow = 2
    iCol = Column_Num_To_Start
    iTable = 0
     
    For Each Tab1 In HTML_Content.getElementsByTagName("table")
    With HTML_Content.getElementsByTagName("table")(iTable)
    For Each Tr In .Rows
    For Each Td In Tr.Cells
     
    Application.ScreenUpdating = False
    Sheets("Feuil2").Visible = True
     
    Set sh = ActiveWorkbook.Worksheets("Feuil2")
     
    With sh
    sh.Select
    .Cells(iRow, iCol).Select
    .Cells(iRow, iCol) = Td.innerText
    iCol = iCol + 1
    End With
     
    Next Td
    iCol = Column_Num_To_Start
    iRow = iRow + 1
    Next Tr
     
    End With
     
    iTable = iTable + 1
    iCol = Column_Num_To_Start
    iRow = iRow + 1
    Next Tab1
     
    Sheets("Feuil2").Visible = False
    Application.ScreenUpdating = True
     
    End Sub

  2. #2
    Expert confirmé
    Homme Profil pro
    retraité
    Inscrit en
    Juin 2012
    Messages
    3 418
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : retraité
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Juin 2012
    Messages : 3 418
    Par défaut
    Bonjour,

    A tester: utiliser une autre méthode, OpenTextFile, pour récupérer le texte du fichier.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    Private Sub cmd_extract_Click()
     
        uf.Hide
        'Application.ScreenUpdating = False
     
        Dim HTML_Content As Object
        Dim Tr As Object
        Dim Td As Object
        Dim Tab1 As Object
        Dim sh As Worksheet
     
        Dim Column_Num_To_Start As Long:    Column_Num_To_Start = 1
        Dim iRow As Long:                   iRow = 2
        Dim iCol As Long:                   iCol = Column_Num_To_Start
        Dim iTable As Long:                 iTable = 0
     
        Set sh = ActiveWorkbook.Worksheets("Feuil2")
        Set HTML_Content = CreateObject("htmlfile")
     
        HTML_Content.body.innerHtml = TexteDe(txt) '--- txt = chemin fichier
     
        For Each Tab1 In HTML_Content.getElementsByTagName("table")
            With HTML_Content.getElementsByTagName("table")(iTable)
                For Each Tr In .Rows
                    For Each Td In Tr.Cells
                        sh.Cells(iRow, iCol) = Td.innerText
                        iCol = iCol + 1
                    Next Td
                    iCol = Column_Num_To_Start
                    iRow = iRow + 1
                Next Tr
                iTable = iTable + 1
                iCol = Column_Num_To_Start
                iRow = iRow + 1
            End With
        Next Tab1
     
        Set sh = Nothing
        Set HTML_Content = Nothing
        'Application.ScreenUpdating = True
    End Sub
     
    Public Function TexteDe(CheminFichier As String) As String
        Dim fso As Scripting.FileSystemObject
        Dim TxtStr As Scripting.TextStream
        Set fso = New Scripting.FileSystemObject
        Set TxtStr = fso.OpenTextFile(CheminFichier, ForReading, False, TristateMixed)
        TexteDe = TxtStr.readall
        Set TxtStr = Nothing
        Set fso = Nothing
    End Function
    Cordialement.

Discussions similaires

  1. Input past end of file - pourriez-vous rappidement m'aider :)
    Par chapeau_melon dans le forum VBScript
    Réponses: 1
    Dernier message: 21/02/2007, 07h51
  2. [VB6] Autre erreur, "Input past end of file" (#62)
    Par Jihnn dans le forum VB 6 et antérieur
    Réponses: 10
    Dernier message: 15/04/2006, 18h18
  3. Run-time error '5':
    Par zazaraignée dans le forum VB 6 et antérieur
    Réponses: 9
    Dernier message: 16/01/2006, 13h53
  4. Réponses: 2
    Dernier message: 15/04/2004, 15h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo