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 :

error9 subscript out of range


Sujet :

Macros et VBA Excel

  1. #1
    Membre averti Avatar de tomy7
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    540
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Points : 391
    Points
    391
    Par défaut error9 subscript out of range
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Set ExcelApp = New Excel.Application
        Set xldoc = ExcelApp.Workbooks.Open(PCF3 & "\Tool 10-8 Change Order Approval Checklist.xls")
        Worksheets("Questions").Range("C3").Value = UserForm1.TextBox2.Value
        Worksheets("Questions").Range("C7").Value = UserForm1.Textbox1.Value
        Worksheets("Questions").Range("C5").Value = UserForm1.combobox1.Value
        Worksheets("Questions").Range("C4").Value = UserForm1.TextBox6.Value
        Worksheets("Questions").Range("C6").Value = UserForm1.TextBox3.Value
        xldoc.SaveAs Filename:=PCF3 & "\Tool 10-8 Change Order Approval Checklist.xls"
        ExcelApp.Quit
        Set xldoc = Nothing
        Set ExcelApp = Nothing
    bug sur la couleur violette, une idée?
    tom

    "Barbar : The rest of the warrior"

    Into the wild....

  2. #2
    Inactif  
    Avatar de ouskel'n'or
    Profil pro
    Inscrit en
    Février 2005
    Messages
    12 464
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 12 464
    Points : 15 543
    Points
    15 543
    Par défaut
    Ce qui veut dire "L'indice n'appartient pas à la sélection"... donc, soit tu as une erreur dans le nom de la feuille soit dans le nom du Textbox, peut-être même de l'userform.

  3. #3
    Membre averti Avatar de tomy7
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    540
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Points : 391
    Points
    391
    Par défaut
    j ai deja du texte dedans je me demande si ça vient pas de la?

    merci de ta présence..."même si je ne lis pas" ... lol
    tom

    "Barbar : The rest of the warrior"

    Into the wild....

  4. #4
    Membre averti Avatar de tomy7
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    540
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Points : 391
    Points
    391
    Par défaut
    quand je mets worksheets("Questions")

    questions est le nom de la feuille qui est représenté sur l'onglet...

    serai t il pas mieu que je remplace Worksheets("Questions") par sheet1?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Set ExcelApp = New Excel.Application
        Set xldoc = ExcelApp.Workbooks.Open(PCF3 & "\Tool 10-8 Change Order Approval Checklist.xls")
        Worksheets("Questions").Range("C3").Value = UserForm1.TextBox2.Value
        Worksheets("Questions").Range("C7").Value = UserForm1.Textbox1.Value
        Worksheets("Questions").Range("C5").Value = UserForm1.combobox1.Value
        Worksheets("Questions").Range("C4").Value = UserForm1.TextBox6.Value
        Worksheets("Questions").Range("C6").Value = UserForm1.TextBox3.Value
        xldoc.SaveAs Filename:=PCF3 & "\Tool 10-8 Change Order Approval Checklist.xls"
        ExcelApp.Quit
        Set xldoc = Nothing
        Set ExcelApp = Nothing
    tom

    "Barbar : The rest of the warrior"

    Into the wild....

  5. #5
    Inactif  
    Avatar de ouskel'n'or
    Profil pro
    Inscrit en
    Février 2005
    Messages
    12 464
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 12 464
    Points : 15 543
    Points
    15 543
    Par défaut
    Ça ne changerait rien. Mais en relisant, je vois une bonne raison pour que tu aies un pb. Teste ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
        Set xldoc = ExcelApp.Workbooks.Open(PCF3 & "\Tool 10-8 Change Order Approval Checklist.xls")
        DoEvents 'laisse au système le tps d'ouvrir ton fichier
        xldoc.Worksheets("Questions").Range("C3").Value = UserForm1.TextBox2.Value
        ... Idem
    Tu as utilisé une instance du classeur que tu n'utilises pas pour ta feuille de calculs. Donc ta macro cherche la feuille dans le classeur contenant la macro.
    A+

  6. #6
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2008
    Messages
    26
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 26
    Points : 31
    Points
    31
    Par défaut
    Tu désignes la feuille ("Questions") mais pas le classeur. Utilise "With"

    Cela donnerait ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    with xldoc
    .Worksheets("Questions").Range("C3").Value = UserForm1.TextBox2.Value
    [etc...]
    end with
    Perso, comme ça je n'ai pas d'erreur...

    Salut.

  7. #7
    Membre averti Avatar de tomy7
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    540
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Points : 391
    Points
    391
    Par défaut
    en effet... tu as completement raison j ai oublié le xldoc. devant workbooks("Questions").....



    merci ouskel'nor
    tom

    "Barbar : The rest of the warrior"

    Into the wild....

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [E-00] "worksheets(i)"-->subscript out of range
    Par anyah dans le forum Macros et VBA Excel
    Réponses: 8
    Dernier message: 03/11/2008, 13h54
  2. 'subscript out of range'
    Par NulenVBA dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 30/10/2008, 10h03
  3. vector subscript out of range: qu'est-ce ?
    Par sa.mh dans le forum C++
    Réponses: 15
    Dernier message: 22/05/2008, 16h47
  4. Réponses: 1
    Dernier message: 23/04/2008, 10h37
  5. vector subscript out of range
    Par nightwar dans le forum SL & STL
    Réponses: 2
    Dernier message: 14/03/2008, 18h35

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