Problème dans la sauvegarder et fermeture de mon fichier Exc
arthur5c
-
yg_be Messages postés 23541 Date d'inscription Statut Contributeur Dernière intervention -
yg_be Messages postés 23541 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour à tous,
J'ai connecté un Formulaire Access avec un Excel pour transférer des données. Bref, cela fonctionne.
Mais c'est la seconde étape qui pose problème. En effet, j'ai l'impression que dans mon code j'ouvre mon Excel pour insérer les données mais je ne sauvegarde pas et ferme pas le document.
Par conséquent, j'ai comme message d'erreur sur Excel :
"Document verrouillé pour modification par microsoft office user"
Merci d'avance
Code :
chemin = Application.CurrentProject.Path & "\" & nom_chemin & ".xlsm"
Set fenetre = New Excel.Application
Set classeur = fenetre.Workbooks.Open(chemin)
Sheets(nom_lot).Select
Do While Cells(taille_tableau, 1) <> ""
taille_tableau = taille_tableau + 1
Loop
MsgBox (taille_tableau)
numero_lot = taille_tableau - 2
classeur.Sheets(nom_lot).Cells(taille_tableau, 1).Value = numero_lot
classeur.Sheets(nom_lot).Cells(taille_tableau, 3).Value = Budget_Quantite
classeur.Sheets(nom_lot).Cells(taille_tableau, 2).Value = excel_Noms
classeur.Sheets(nom_lot).Cells(taille_tableau, 4).Value = excel_hscode
classeur.Sheets(nom_lot).Cells(taille_tableau, 6).Value = excel_fabricants
classeur.Sheets(nom_lot).Cells(taille_tableau, 7).Value = excel_modeles
classeur.Sheets(nom_lot).Cells(taille_tableau, 8).Value = excel_prix
MsgBox ("Donnée copiée")
fenetre.Application.DisplayAlerts = False
fenetre.Quit
Set fenetre = Nothing
Set classeur = Nothing
J'ai connecté un Formulaire Access avec un Excel pour transférer des données. Bref, cela fonctionne.
Mais c'est la seconde étape qui pose problème. En effet, j'ai l'impression que dans mon code j'ouvre mon Excel pour insérer les données mais je ne sauvegarde pas et ferme pas le document.
Par conséquent, j'ai comme message d'erreur sur Excel :
"Document verrouillé pour modification par microsoft office user"
Merci d'avance
Code :
chemin = Application.CurrentProject.Path & "\" & nom_chemin & ".xlsm"
Set fenetre = New Excel.Application
Set classeur = fenetre.Workbooks.Open(chemin)
Sheets(nom_lot).Select
Do While Cells(taille_tableau, 1) <> ""
taille_tableau = taille_tableau + 1
Loop
MsgBox (taille_tableau)
numero_lot = taille_tableau - 2
classeur.Sheets(nom_lot).Cells(taille_tableau, 1).Value = numero_lot
classeur.Sheets(nom_lot).Cells(taille_tableau, 3).Value = Budget_Quantite
classeur.Sheets(nom_lot).Cells(taille_tableau, 2).Value = excel_Noms
classeur.Sheets(nom_lot).Cells(taille_tableau, 4).Value = excel_hscode
classeur.Sheets(nom_lot).Cells(taille_tableau, 6).Value = excel_fabricants
classeur.Sheets(nom_lot).Cells(taille_tableau, 7).Value = excel_modeles
classeur.Sheets(nom_lot).Cells(taille_tableau, 8).Value = excel_prix
MsgBox ("Donnée copiée")
fenetre.Application.DisplayAlerts = False
fenetre.Quit
Set fenetre = Nothing
Set classeur = Nothing
A voir également:
- Problème dans la sauvegarder et fermeture de mon fichier Exc
- Fichier bin - Guide
- Comment réduire la taille d'un fichier - Guide
- Fichier epub - Guide
- Fichier rar - Guide
- Fichier .dat - Guide
4 réponses
yg_be
Messages postés
23541
Date d'inscription
Statut
Contributeur
Dernière intervention
Ambassadeur
1 584
bonjour,
Peut-être en ajoutant
Peut-être en ajoutant
call classeur.close()?
Toujours le même message :
Run-time error '-2147417848 (80010108)':
Automation error
Puis pour le debug, il me surlonge la ligne : Call classeur.Close(True)
Run-time error '-2147417848 (80010108)':
Automation error
Puis pour le debug, il me surlonge la ligne : Call classeur.Close(True)
Peux-tu montrer comment tu as adapté ton code? Teins compte de ceci: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
Option Compare Database Option Explicit Private Sub Commande38_Click() Dim requete, requete2 As Recordset Dim sql, resultat, excel_Noms, excel_hscode, excel_fabricants, excel_modeles As String Dim excel_prix As Currency Dim taille_tableau, numero_lot As Integer taille_tableau = 2 If Budget_Nom = "" Then MsgBox ("Noms du documents de Budgetisation") ElseIf Budget_Lot = "" Then MsgBox ("Numero de Lots vide") ElseIf Choix_ID = "" Then MsgBox ("Numero d'ID vide") ElseIf Budget_Quantite = "" Then MsgBox ("Quantité vide") Else If MsgBox("Avez-vous fermer votre Excel de Budgetisation ?", vbYesNo, "Fermeture de la Budgetisation") = vbYes Then Dim fenetre As Excel.Application, classeur As Excel.Workbook Dim chemin As String, recuperation, nom_chemin, nom_lot As String nom_chemin = Budget_Nom nom_lot = "Lot1" sql = "SELECT Noms, HScode, Fabricants, Modeles, Prix FROM T_BDD WHERE ID= " & Choix_ID & ";" Set requete = CurrentDb.OpenRecordset(sql) requete.MoveFirst excel_Noms = requete("Noms") excel_hscode = requete("HScode") excel_fabricants = requete("Fabricants") excel_modeles = requete("Modeles") excel_prix = requete("Prix") chemin = Application.CurrentProject.Path & "\" & nom_chemin & ".xlsm" Set fenetre = New Excel.Application Set classeur = fenetre.Workbooks.Open(chemin) Sheets(nom_lot).Select Do While Cells(taille_tableau, 1) <> "" taille_tableau = taille_tableau + 1 Loop MsgBox (taille_tableau) numero_lot = taille_tableau - 2 classeur.Sheets(nom_lot).Cells(taille_tableau, 1).Value = numero_lot classeur.Sheets(nom_lot).Cells(taille_tableau, 3).Value = Budget_Quantite classeur.Sheets(nom_lot).Cells(taille_tableau, 2).Value = excel_Noms classeur.Sheets(nom_lot).Cells(taille_tableau, 4).Value = excel_hscode classeur.Sheets(nom_lot).Cells(taille_tableau, 6).Value = excel_fabricants classeur.Sheets(nom_lot).Cells(taille_tableau, 7).Value = excel_modeles classeur.Sheets(nom_lot).Cells(taille_tableau, 8).Value = excel_prix MsgBox ("Donnée copiée") fenetre.Application.DisplayAlerts = False fenetre.Quit Call classeur.Close(True) Set fenetre = Nothing Set classeur = Nothing End If End If End Sub