[ACCESS] Exectuer Macro Excel dans Access
Fermé
artamys
Messages postés
120
Date d'inscription
lundi 18 juin 2007
Statut
Membre
Dernière intervention
9 mars 2018
-
4 nov. 2008 à 14:04
artamys Messages postés 120 Date d'inscription lundi 18 juin 2007 Statut Membre Dernière intervention 9 mars 2018 - 4 nov. 2008 à 15:07
artamys Messages postés 120 Date d'inscription lundi 18 juin 2007 Statut Membre Dernière intervention 9 mars 2018 - 4 nov. 2008 à 15:07
A voir également:
- [ACCESS] Exectuer Macro Excel dans Access
- Liste déroulante excel - Guide
- Formule excel - Guide
- You don't have permission to access this resource ✓ - Forum Internet / Réseaux sociaux
- Trying to access array offset on value of type bool ✓ - Forum PHP
- Déplacer une colonne excel - Guide
2 réponses
michel_m
Messages postés
16593
Date d'inscription
lundi 12 septembre 2005
Statut
Contributeur
Dernière intervention
23 mars 2023
3 292
4 nov. 2008 à 14:51
4 nov. 2008 à 14:51
Bonjour
Au préalable, il faut cocher la référence "Microsoft Excel X.y library" dans outils-références de l'éditeur VB
à partir d'une sub access
Dim appliXL As Excel.Application
Dim classeur As Excel.Workbook
' Par exemplr: On veut ouvrir le classeur concerné
Set appliXL = CreateObject("Excel.Application")
par exemple:
Set classeur= xlApp.Workbooks.Open("chemin+nom du classeur concerné")
ton code
set classeur=nothing
appliXL.Quit
set appliXL=nothing
nota: certains antivrus trouvent suspect l'instruction "Quit"... Passer outre
Au préalable, il faut cocher la référence "Microsoft Excel X.y library" dans outils-références de l'éditeur VB
à partir d'une sub access
Dim appliXL As Excel.Application
Dim classeur As Excel.Workbook
' Par exemplr: On veut ouvrir le classeur concerné
Set appliXL = CreateObject("Excel.Application")
par exemple:
Set classeur= xlApp.Workbooks.Open("chemin+nom du classeur concerné")
ton code
set classeur=nothing
appliXL.Quit
set appliXL=nothing
nota: certains antivrus trouvent suspect l'instruction "Quit"... Passer outre
artamys
Messages postés
120
Date d'inscription
lundi 18 juin 2007
Statut
Membre
Dernière intervention
9 mars 2018
7
4 nov. 2008 à 15:07
4 nov. 2008 à 15:07
merci michel,
La librairie est cochée par le programme en amont qui vérifie si la librairie est active et a défaut elle l'active.
voici mon code, il ne pose pas de probleme. il marche mal pour une raison indéterminée.
Private Sub Extraction_DEI_Projet_Click()
Call ReferenceActive("Excel")
'fonction de vérification de l'existence de la bibliotheque excel
If Not ReferenceActive("Excel") Then ActiverReference "Excel.exe"
Dim AccApp As Access.Application
Dim ref As Reference
Set ref = References!Access
Dim ref2 As Reference
Set ref2 = References!Excel
Dim DayJour As Integer
Dim MonthJour As Integer
Dim YearJour As Integer
Dim heureJour As Integer
Dim MinuteJour As Integer
Dim Dateinstant As Date
Dateinstant = Now()
HeureJour = Hour(Dateinstant)
MinuteJour = Minute(Dateinstant)
DayJour = Day(Dateinstant)
MonthJour = Month(Dateinstant)
Dim XlApp As Excel.Application
Dim XlSheet As Excel.Worksheet
Dim XlBook As Excel.Workbook
Set XlApp = CreateObject("Excel.Application")
XlApp.SheetsInNewWorkbook = 1
Dim tempo As Integer
tempo = heureJour & MinuteJour
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Extraction_Projet", "..\DeskTop\Extraction DEI" & DayJour & MonthJour & tempo & ".xls"
XlApp.Visible = True
Set XlBook = XlApp.Workbooks.Open("..\DeskTop\Extraction DEI" & DayJour & MonthJour & tempo & ".xls")
XlBook.Worksheets(1).Visible = True
XlBook.Worksheets(1).Select
XlBook.Worksheets(1).Cells.Select
XlBook.Worksheets(1).Columns.AutoFit
XlBook.Worksheets(1).Columns("B:B").Select
With Selection.Font
.Name = "arial"
End With
' attention cette partie fonctionne de maniere aléatoire. une fois il passe une fois il dit que la selection n'est pas définie...
Set XlSheet = XlBook.Worksheets(1)
XlSheet.Columns("B:B").Select
'Set Selection = XlSheet.Columns(0, 2).Select
Set test = XlSheet.Columns
With test.Width = 45
End With
XlSheet.Cells(1, 1).Select
XlSheet.Columns("C:C").Select
'Set Selection = XlSheet.Columns("C:C").Select
Selection.ColumnWidth = 50
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
' attention cette partie fonctionne de maniere aléatoire. une fois il passe une fois il dit que la selection n'est pas définie...
End Sub
La librairie est cochée par le programme en amont qui vérifie si la librairie est active et a défaut elle l'active.
voici mon code, il ne pose pas de probleme. il marche mal pour une raison indéterminée.
Private Sub Extraction_DEI_Projet_Click()
Call ReferenceActive("Excel")
'fonction de vérification de l'existence de la bibliotheque excel
If Not ReferenceActive("Excel") Then ActiverReference "Excel.exe"
Dim AccApp As Access.Application
Dim ref As Reference
Set ref = References!Access
Dim ref2 As Reference
Set ref2 = References!Excel
Dim DayJour As Integer
Dim MonthJour As Integer
Dim YearJour As Integer
Dim heureJour As Integer
Dim MinuteJour As Integer
Dim Dateinstant As Date
Dateinstant = Now()
HeureJour = Hour(Dateinstant)
MinuteJour = Minute(Dateinstant)
DayJour = Day(Dateinstant)
MonthJour = Month(Dateinstant)
Dim XlApp As Excel.Application
Dim XlSheet As Excel.Worksheet
Dim XlBook As Excel.Workbook
Set XlApp = CreateObject("Excel.Application")
XlApp.SheetsInNewWorkbook = 1
Dim tempo As Integer
tempo = heureJour & MinuteJour
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Extraction_Projet", "..\DeskTop\Extraction DEI" & DayJour & MonthJour & tempo & ".xls"
XlApp.Visible = True
Set XlBook = XlApp.Workbooks.Open("..\DeskTop\Extraction DEI" & DayJour & MonthJour & tempo & ".xls")
XlBook.Worksheets(1).Visible = True
XlBook.Worksheets(1).Select
XlBook.Worksheets(1).Cells.Select
XlBook.Worksheets(1).Columns.AutoFit
XlBook.Worksheets(1).Columns("B:B").Select
With Selection.Font
.Name = "arial"
End With
' attention cette partie fonctionne de maniere aléatoire. une fois il passe une fois il dit que la selection n'est pas définie...
Set XlSheet = XlBook.Worksheets(1)
XlSheet.Columns("B:B").Select
'Set Selection = XlSheet.Columns(0, 2).Select
Set test = XlSheet.Columns
With test.Width = 45
End With
XlSheet.Cells(1, 1).Select
XlSheet.Columns("C:C").Select
'Set Selection = XlSheet.Columns("C:C").Select
Selection.ColumnWidth = 50
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
' attention cette partie fonctionne de maniere aléatoire. une fois il passe une fois il dit que la selection n'est pas définie...
End Sub