Bonjour,
Je désire piloter MS Excel depuis MS Access.
De façon à éviter les références à Microsoft Excel 12 / 13 / 16 dans le menu Tools /references, je veux utiliser la méthode du "Late binding". Malheureusement, j'ai quelques problèmes avec certaines fonctions Excel...
Je ne parviens pas à utiliser ACTIVECELL de MS Excel.
Voici mon code VBA de MS Access pour rajouter une ligne à une feuille Excel qui contient déjà quelques lignes de données.
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
50
51
52 Function demoEarly_Late() '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.. 'These early binding lines used during development : 'Dim objXL As Excel.Application 'Dim objWkbk As Workbook 'Dim objSht As Worksheet 'These late binding lines used for production to avoid reference to Excel 11, 12 or 16 Dim objXL As Object Dim objWkbk As Object Dim objSht As Object Dim R As Integer 'R = Row nbr in Excel sheet (I should not have to deal with more than 32000 rows !) Set objXL = CreateObject("Excel.Application") Set objWkbk = objXL.Workbooks.Open("C:/Temp/Test.xlsx") 'The first sheet with data is the sheet called 'Musees' Set objSht = objWkbk.Worksheets("Musees") objXL.Visible = True 'syntax for late binding : objWkbk.Sheets("Musees").Select 'find last cell used objWkbk.Sheets("Musees").Range("A65536").End(xlUp).Select 'syntax for early binding (development mode) : 'R = activecell.Row 'the last row with data 'syntax for late binding (Prod mode) : 'R = objWkbk.Sheets("Musees").ActiveCell.Row 'ERREUR : Object doesn't support this property or method !!!!! R = objSht.ActiveCell.Row 'ERREUR : Object doesn't support this property or method !!!!! 'The following line works perfectly the first time you use it. If you run this function again (in a loop), it will fail ! 'R = ActiveWindow.ActiveCell.Row R = R + 1 objWkbk.Sheets("Musees").Cells(R, 1).Value = "Blah Blah Blah" objWkbk.Save objWkbk.Close objXL.Quit Set objWkbk = Nothing objSht = Nothing objXL = Nothing End Function




Répondre avec citation






Partager