VBA : Erreur d'exécution '91' : Variable objet ou variable de bloc With non déf
Résolu
KoukxLeMeteor
Messages postés
2
Date d'inscription
Statut
Membre
Dernière intervention
-
KoukxLeMeteor Messages postés 2 Date d'inscription Statut Membre Dernière intervention -
KoukxLeMeteor Messages postés 2 Date d'inscription Statut Membre Dernière intervention -
Bonjour à toutes et à tous,
Je suis sur un projet VBA depuis quelques jours et à vrai dire je commence à galérer
J'ai une erreur d'exécution '91' : Variable objet ou variable de bloc With non définie
L'erreur est indiquée à cette ligne :
Do While iFeuille <= wbCatalogue.Sheets.Count
Je vous remercie d'avance pour votre aide et vos propositions.
Voici mon code :
Private Sub btnGenereSupports_Click()
Dim wbCatalogue As Workbook
Dim wsListe As Worksheet
Dim iCat As Integer
Dim iFeuille As Integer
Dim iInfo As Integer
Dim colonne As String
Dim chemin As String
Dim prefixe As String
Dim version As String
Dim cheminComplet As String
Dim iObjet As Integer
Dim iAttribut As Integer
Dim iCtrle As Integer
Dim iCle As Integer
Dim typeValeur As Integer
Dim valInt As Integer
Dim valStr As String
Dim nbCol As Integer
Dim NoCol As Integer, Cell As Range
Dim NoLig As Long, Derlig As Long, Var As Variant
Dim paramC As Variant
Dim nameC As Variant
Dim nbrC As Integer
Set wsListe = Application.ThisWorkbook.Sheets("Liste")
' récup les valeurs sur la 1ere feuille
chemin = wsListe.Cells(1, 8)
prefixe = wsListe.Cells(2, 8)
iCat = 2
Do While Not IsEmpty(wsListe.Cells(iCat, 1))
' si avancement est renseigné on ne le refait pas
If IsEmpty(wsListe.Cells(iCat, 3)) Then
nomCatalogue = wsListe.Cells(iCat, 1)
version = wsListe.Cells(iCat, 2)
' ouvrir le fichier catalogue
cheminComplet = chemin & "\" & prefixe & nomCatalogue & "_v" & version & ".xlsx"
Set wbCatalogue = Workbooks.Open(cheminComplet)
iFeuille = 1
Do While iFeuille <= wbCatalogue.Sheets.Count
' nom de la feuille
nomSupport = wbCatalogue.Sheets(iFeuille).Name
' ne pas traiter la feuille de suivi
If nomSupport <> "-Suivi-" And Left(nomSupport, 1) <> "#" Then
' supports de saisie
If wbCatalogue.Sheets(iFeuille).Cells(1, 1) = "Info" Then
' ====================================================================================================
' Ajouter les traitements ici
' ====================================================================================================
Derlig = Split(wsListe.UsedRange.Address, "$")(4)
NoCol = 1
'Suppression "d'" et "l'" ET Remplacement espace-->underscore
For NoLig = 1 To Derlig
Var = wsListe.Cells(NoLig, NoCol)
Debug.Print Var
Debug.Print Replace(Var, " ", "_")
Debug.Print Replace(Replace(Var, "d'", ""), "l'", "")
Next
'Set wsListe = Nothing
'Dé-fusion des cellules à droite du tableau
Range("H1").MergeCells = False
'Insertion des colonnes G à T
paramC = Array("format", "clé", "ctrl1", "p11", "p12", "p13", "ctrl21", "p21", "p22", "p23", "ctrl3", "p31", "p32", "p33")
nameC = Array("G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T")
x = 0
nbrC = 7
Do While x <= 14
Range(nameC(x) + "1").Select
Selection.EntireColumn.Insert
Cells(1, nbrC) = paramC(x)
nbrC = nbrC + 1
x = x + 1
Loop
'If underline X dans 8 et 1 dans 13
NumRows = Range("A1", Range("A1").End(xlDown)).Rows.Count
Range("A1").Select
For x = 1 To NumRows
Debug.Print ActiveCell.Select
If ActiveCell.Select.Font.Underline = True Then
Range(x, 13) = 1
Range(x, 8) = "X"
End If
Next
'If Obligatoire = O => Ctrl1 = 1
NumRows = Range("A3", Range("A3").End(xlDown)).Rows.Count
Range("A3").Select
For x = 1 To NumRows
If ActiveCell.Select = "O" Then
Range(x, 9) = 1
End If
Next
'If colonne commentaire = "à prendre dans" => créer un ctrl 7 param2=code
NumRows = Range("A4", Range("A4").End(xlDown)).Rows.Count
Range("A4").Select
valStr = ActiveCell.Select.Text
If InStr(1, valStr, "à prendre dans") Then
End If
End If
End If
iFeuille = iFeuille + 1
Loop
' fermer le catalogue en enregistrant
wbCatalogue.Close SaveChanges:=True
wsListe.Cells(iCat, 3) = "fait"
End If
iCat = iCat + 1
Loop
End Sub
Je suis sur un projet VBA depuis quelques jours et à vrai dire je commence à galérer
J'ai une erreur d'exécution '91' : Variable objet ou variable de bloc With non définie
L'erreur est indiquée à cette ligne :
Do While iFeuille <= wbCatalogue.Sheets.Count
Je vous remercie d'avance pour votre aide et vos propositions.
Voici mon code :
Private Sub btnGenereSupports_Click()
Dim wbCatalogue As Workbook
Dim wsListe As Worksheet
Dim iCat As Integer
Dim iFeuille As Integer
Dim iInfo As Integer
Dim colonne As String
Dim chemin As String
Dim prefixe As String
Dim version As String
Dim cheminComplet As String
Dim iObjet As Integer
Dim iAttribut As Integer
Dim iCtrle As Integer
Dim iCle As Integer
Dim typeValeur As Integer
Dim valInt As Integer
Dim valStr As String
Dim nbCol As Integer
Dim NoCol As Integer, Cell As Range
Dim NoLig As Long, Derlig As Long, Var As Variant
Dim paramC As Variant
Dim nameC As Variant
Dim nbrC As Integer
Set wsListe = Application.ThisWorkbook.Sheets("Liste")
' récup les valeurs sur la 1ere feuille
chemin = wsListe.Cells(1, 8)
prefixe = wsListe.Cells(2, 8)
iCat = 2
Do While Not IsEmpty(wsListe.Cells(iCat, 1))
' si avancement est renseigné on ne le refait pas
If IsEmpty(wsListe.Cells(iCat, 3)) Then
nomCatalogue = wsListe.Cells(iCat, 1)
version = wsListe.Cells(iCat, 2)
' ouvrir le fichier catalogue
cheminComplet = chemin & "\" & prefixe & nomCatalogue & "_v" & version & ".xlsx"
Set wbCatalogue = Workbooks.Open(cheminComplet)
iFeuille = 1
Do While iFeuille <= wbCatalogue.Sheets.Count
' nom de la feuille
nomSupport = wbCatalogue.Sheets(iFeuille).Name
' ne pas traiter la feuille de suivi
If nomSupport <> "-Suivi-" And Left(nomSupport, 1) <> "#" Then
' supports de saisie
If wbCatalogue.Sheets(iFeuille).Cells(1, 1) = "Info" Then
' ====================================================================================================
' Ajouter les traitements ici
' ====================================================================================================
Derlig = Split(wsListe.UsedRange.Address, "$")(4)
NoCol = 1
'Suppression "d'" et "l'" ET Remplacement espace-->underscore
For NoLig = 1 To Derlig
Var = wsListe.Cells(NoLig, NoCol)
Debug.Print Var
Debug.Print Replace(Var, " ", "_")
Debug.Print Replace(Replace(Var, "d'", ""), "l'", "")
Next
'Set wsListe = Nothing
'Dé-fusion des cellules à droite du tableau
Range("H1").MergeCells = False
'Insertion des colonnes G à T
paramC = Array("format", "clé", "ctrl1", "p11", "p12", "p13", "ctrl21", "p21", "p22", "p23", "ctrl3", "p31", "p32", "p33")
nameC = Array("G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T")
x = 0
nbrC = 7
Do While x <= 14
Range(nameC(x) + "1").Select
Selection.EntireColumn.Insert
Cells(1, nbrC) = paramC(x)
nbrC = nbrC + 1
x = x + 1
Loop
'If underline X dans 8 et 1 dans 13
NumRows = Range("A1", Range("A1").End(xlDown)).Rows.Count
Range("A1").Select
For x = 1 To NumRows
Debug.Print ActiveCell.Select
If ActiveCell.Select.Font.Underline = True Then
Range(x, 13) = 1
Range(x, 8) = "X"
End If
Next
'If Obligatoire = O => Ctrl1 = 1
NumRows = Range("A3", Range("A3").End(xlDown)).Rows.Count
Range("A3").Select
For x = 1 To NumRows
If ActiveCell.Select = "O" Then
Range(x, 9) = 1
End If
Next
'If colonne commentaire = "à prendre dans" => créer un ctrl 7 param2=code
NumRows = Range("A4", Range("A4").End(xlDown)).Rows.Count
Range("A4").Select
valStr = ActiveCell.Select.Text
If InStr(1, valStr, "à prendre dans") Then
End If
End If
End If
iFeuille = iFeuille + 1
Loop
' fermer le catalogue en enregistrant
wbCatalogue.Close SaveChanges:=True
wsListe.Cells(iCat, 3) = "fait"
End If
iCat = iCat + 1
Loop
End Sub
A voir également:
- Variable objet ou variable de bloc with non définie
- L'indice n'appartient pas à la sélection vba - Forum VB / VBA
- Incompatibilité de type vba ✓ - Forum Programmation
- Excel compter cellule couleur sans vba - Guide
- Vba attendre 1 seconde ✓ - Forum VB / VBA
- Vba ouvrir un fichier excel avec chemin ✓ - Forum VB / VBA
Merci pour votre réponse. Je viens de trouver la réponse, j'ai honte ^^ Le fichier excel sur lequel j'allais travailler était ouvert.
Bonne fin de journée