Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1549 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Problème importation

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Problème importation

n°2191575
benny84
Posté le 23-05-2013 à 22:23:38  profilanswer
 

Bonjour, j'essaie depuis quelques jours d'importer des données d'un fichier à l'autre et j'obtiens toujours un message d'erreur. Je ne suis pas assez avancé en programmation vba pour corriger mon problème. J'obtiens le message suivant : [Variable objet ou variable bloc With non définie (erreur 91)].
 
Mon message d'erreur arrive à : (OldTaux_1.Names("Nom_i" ).RefersToRange.Value = Varia)
 
Voici mon code :  
 
Private Sub Importer_tout_Click()  
 
Dim OldValidation As Worksheet, NewValidation As Worksheet  
Dim monfichier As String, Nomdufichier As String  
Dim entier As Long  
Dim OldWb As Workbook, NewWb As Workbook  
Dim OldTaux_1 As Worksheet, OldHist_1 As Worksheet, OldVie_1 As Worksheet, OldIld_1 As Worksheet
 Dim NewTaux_1 As Worksheet, NewHist_1 As Worksheet, NewVie_1 As Worksheet, NewIld_1 As Worksheet
 Dim Nom_i As String  
Dim Varia As Variant  
 
 
Application.ScreenUpdating = False  
monfichier = Fichier_import.Value  
 
'Obtenir le nom de l'ancien fichier dans le textbox  
entier = Len(monfichier) 'le nombre de caractère dans mon fichier  
Do Until Mid(monfichier, entier, 1) = "\"  
entier = entier - 1  
Loop  
 
Nomdufichier = Right(monfichier, Len(monfichier) - entier) 'Permet d'obtenir le nom du fichier sans le début
 
Set NewWb = ActiveWorkbook  
Set NewTaux_1 = GetWsFromCodeName(NewWb, "Sheet1" )  
Set NewHist_1 = GetWsFromCodeName(NewWb, "Sheet2" )  
Set NewVie_1 = GetWsFromCodeName(NewWb, "Sheet3" )  
 
Workbooks.Open (monfichier)  
Set OldWb = Workbooks(Nomdufichier)  
Set OldTaux_1 = GetWsFromCodeName(OldWb, "Sheet1" )  
Set OldHist_1 = GetWsFromCodeName(OldWb, "Sheet2" )  
Set OldVie_1 = GetWsFromCodeName(OldWb, "Sheet3" )  
 
 
For i = 1 To 2  
Set Varia = Nothing  
Workbooks(Nomdufichier).Activate  
OldTaux_1.Names("Nom_i" ).RefersToRange.Value = Varia
Windows(NewWb).Activate  
NewTaux_1.Names("Nom_i" ).RefersToRange.Value = Varia  
Next i  
 
OldWb.Close  
Application.ScreenUpdating = True  
End Sub  
 
______________________  
' Fonction importer le fichier dans la boîte  
Private Sub Parcourir_Click()  
With Application.FileDialog(msoFileDialogOpen)  
.AllowMultiSelect = False  
.Show  
UserForm1.Fichier_import.Text = .SelectedItems(1)  
End With  
 
End Sub  
 
_______________________  
Function GetWsFromCodeName(wb As Workbook, CodeName As String) As Excel.Worksheet
 Dim ws As Excel.Worksheet  
 
For Each ws In wb.Worksheets  
If ws.CodeName = CodeName Then  
Set GetWsFromCodeName = ws  
Exit For  
End If  
Next ws  
End Function  
 
 
Merci bcp à l'avance !  :)

mood
Publicité
Posté le 23-05-2013 à 22:23:38  profilanswer
 

n°2191583
Marc L
Posté le 24-05-2013 à 00:42:22  profilanswer
 

 
           Bonsoir.        Édites ton message et utilise l'icône prévu pour le code, merci.
 
           Sinon rien qu'en consultant l'aide de la propriété  RefersToRange  …
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Problème importation

 

Sujets relatifs
Probleme importation fichier.sql trop volumineuxprobleme importation .CSV vers MySQL
Problème importation XamppProblème à l'importation B.D.D MySQL
Problème d'importation PhpMyAdminProblème d'importation de bdd
[MYSQL] Problème Charset importation données - BIGDUMPProblème création module importation
PROBLEME DE DATE LORS DE L'IMPORTATION SOUS EXCELProbleme [VBA] importation données excel dans Access
Plus de sujets relatifs à : Problème importation


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR