Vba access error 440 method run of object '_application' failed

Fermé
dianedg Messages postés 22 Date d'inscription mercredi 5 mars 2014 Statut Membre Dernière intervention 19 juillet 2016 - 15 juin 2016 à 14:34
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 - 15 juin 2016 à 19:02
Bonjour,
J'ai un code vba sous access qui doit ouvrir un fichier excel et lancer la macro qu'il contient.
J'obtiens cette erreur: error 440 method run of object '_application' failed

Cependant, la macro dans excel s’exécute puisqu'elle doit créer 2 fichiers et qu'ils sont effectivement créés correctement.

Est-ce que ça peut venir des références à cocher ?
Ci-dessous le code vba dans Access.

Merci pour votre aide
Diane



Sub Thawing_VialCompatibility()

'Export table
'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "BatchToVialThawing_Compatibility", "C:\monchemin\Macros\Batch.xlsx", , , True

'Execute macro for compatibility analysis
Dim xl As Excel.Application
Dim wbk As Excel.Workbook


'Démarrer Excel et le rendre visible
Set xl = New Excel.Application
xl.Visible = True

'Ouvrir le classeur qui contient les macros
Set wbk = xl.Workbooks.Open("C:\monchemin\06_Data management\Macros\TemplateFile.xlsm")

'Exécuter une macro Excel
xl.Run "CheckCompatibility" '<<<<L'ERREUR APPARAIT ICI

'Fermer le classeur sans l'enregistrer
wbk.Close False
Set wbk = Nothing

'Quitter Excel
xl.Quit
Set xl = Nothing


End Sub

1 réponse

f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701
15 juin 2016 à 14:57
Bonjour,

xl.Application.Run ("'" & wbk.Name & "'!test")
0
dianedg Messages postés 22 Date d'inscription mercredi 5 mars 2014 Statut Membre Dernière intervention 19 juillet 2016 1
15 juin 2016 à 16:57
Merci pour la réponse. J'ai testé, j'ai toujours la même erreur.
Si ça peut aider, voici la macro dans le fichier excel:
Merci d'avance.
Diane

Sub CheckCompatibility()

'look for DataExportComplete file
Report = "C:\monchemin\BatchToVialThawing_Compatibility.xlsx"

'define batch number
batch = InputBox("Record the Lot N° for batch:")

Workbooks.Open Filename:=Report 'open exported file from database
Range("A2:G257").Copy 'copy data from selected columns

Windows("Template_BatchToVialThawing_Compatibility.xlsm").Activate 'paste in TemplateFile
Range("A5").PasteSpecial
Range("A5:G260").Sort Key1:=Range("C5:C260")
Columns("A:G").EntireColumn.AutoFit 'format columns
Range("A5:G260").HorizontalAlignment = xlCenter
Range("B2").Value = batch

Workbooks("BatchToVialThawing_Compatibility.xlsx").Activate
Range("A1:G257").Delete 'delete data in Compatibility file to allow re-export
Workbooks("BatchToVialThawing_Compatibility.xlsx").Close True 'close file

'print pdf report
'Path = "C:\moncheminpdf"
'ChDir Path
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\moncheminpdf\" & batch & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False

Application.DisplayAlerts = False 'no alert for recording file without macro

'save file with batch number
ChDir "C:\moncheminxls"
ActiveWorkbook.SaveAs Filename:= _
"C:\moncheminxls\" & batch & ".xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False

Application.DisplayAlerts = True

ActiveWorkbook.Close True
Workbooks("Template_BatchToVialThawing_Compatibility.xlsm").Close False

End Sub


0
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701 > dianedg Messages postés 22 Date d'inscription mercredi 5 mars 2014 Statut Membre Dernière intervention 19 juillet 2016
15 juin 2016 à 18:47
Re,

Chez moi le code que j'ai mis marche, je l'ai teste avec un fichier a moi et aucun probleme. Je vais voir avec votre code "complet"
0
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701 > f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024
15 juin 2016 à 19:02
Re,
J'ai pirs un bouton pour lancer, mais un appel de votre procedure marche pareil
Chemin a adapter mais ca marche, jusqu'a une erreur pour le format PDF, mais c'est normal, je n'ai pas le bon fichier xlsx et xlsm

Private Sub Commande16_Click()
'Execute macro for compatibility analysis
Dim xl As Excel.Application
Dim wbk As Excel.Workbook
'Démarrer Excel et le rendre visible
Set xl = New Excel.Application
xl.Visible = True
'Ouvrir le classeur qui contient les macros
Set wbk = xl.Workbooks.Open("C:\Users\SWF\Downloads\Template_BatchToVialThawing_Compatibility.xlsm")
'Exécuter une macro Excel
xl.Application.Run ("'" & wbk.Name & "'!CheckCompatibility")
'Fermer le classeur sans l'enregistrer
wbk.Close False
Set wbk = Nothing

'Quitter Excel
xl.Quit
Set xl = Nothing
End Sub
0