Bonjour,
Dans le cadre d’un menu général, j’ai remplacé la fonction « HandleButtonClick() » d’une option par le code suivant pour ouvrir un fichier xlsx.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 Private Sub Option3_Click() 'Requires to define in Tools menu the reference to Microsoft Excel Object Library 'Beware : this object library may be different from PC to PC : version 11 or 12 or.. Dim objXL As Excel.Application Dim objWkbk As Workbook Dim objSht As Worksheet Dim i As Integer 'ouvrir Excel 'Si Excel est déjà ouvert sur le PC, GetObject suffit. On Local Error Resume Next Set objXL = GetObject(, "Excel.Application") 'Par contre, si Excel n'est pas encore lancé sur le PC, alors il faut le faire par ce CreateObject If Nothing Is objXL Then Set objXL = CreateObject("Excel.Application") End If On Error GoTo 0 'ouvrir le fichier Set objWkbk = objXL.Workbooks.Open("D:\Mes documents\Emilie\Emploi du Temps\Documents de travail.xlsx") 'The sheet with our data is the first one Set objSht = objWkbk.Worksheets(1) objXL.Visible = True 'Make this sheet the active one when we open the Spreadsheet objSht.Activate 'Travailler sur le tableur Excel. For example, set titles in grey. Gris clair = color15 Gris foncé= 16 With objSht 'il y a 3 colonnes 'For i = 1 To 3 '.Cells(1, i).Interior.ColorIndex = 15 '.Cells(1, i).WrapText = True 'Next i End With 'Fermer le fichier et le sauver 'objWkbk.Close True 'libérer les pointeurs Set objWkbk = Nothing Set objXL = Nothing End Sub
Le fichier s’ouvre mais bizarrement cad qu’un fois sur deux il reste en arrière-plan après ouverture .
Cherchez l’erreur ??
Merci
Roland
Partager