bonjour,
encore en gèrre avec access. cette fois j'ai un autre problème.
je souhaite importer d'une manière automatique un fichier excel. donc pour commencer j'ai créer un bouton dans un formulaire qui est liè à une macro qui peux executer du code dans un module qui a pour but de réaliser un explorateur de fichier.
mon problème est quand j'appel la fonction OpenFile(C:\Document\)
cela me renvoi une erreur "l'objet ne contient pas d'objet d'automatisation 'C' "
mon code est le suivant
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 Option Compare Database Public Type OpenFileName lStructSize As Long hwndOwner As Long Instance As Long lpstrFilter As String lpstrCustomFilter As String nMaxCustomFilter As Long nFilterIndex As Long lpstrFile As String nMaxFile As Long lpstrFileTitle As String nMaxFileTitle As Long lpstrInitialDir As String lpstrTitle As String Flags As Long nFileOffset As Integer nFileExtension As Integer lpstrDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String End Type Public Declare Function GetOpenFileName Lib "comdlg32.dll" _ Alias "GetOpenFileNameA" (pOpenfilename As OpenFileName) As Long Public Const OFN_AllowMultiSelect = &H200 Public Const OFN_CreatePrompt = &H2000 Public Const OFN_EnableHook = &H20 Public Const OFN_EnableTemplate = &H40 Public Const OFN_EnableTemplateHandle = &H80 Public Const OFN_EXPLORER = &H80000 Public Const OFN_ExtensionDifferent = &H400 Public Const OFN_FileMustExist = &H1000 Public Const OFN_HideReadOnly = &H4 Public Const OFN_LongNames = &H200000 Public Const OFN_NoChangeDir = &H8 Public Const OFN_NoDeReferenceLinks = &H100000 Public Const OFN_NoLongNames = &H40000 Public Const OFN_NoNetWorkButton = &H20000 Public Const OFN_NoReadOnlyReturn = &H8000 Public Const OFN_NoTestFileCreate = &H10000 Public Const OFN_NoValiDate = &H100 Public Const OFN_OverWritePrompt = &H2 Public Const OFN_PathMustExist = &H800 Public Const OFN_ReadOnly = &H1 Public Const OFN_ShareAware = &H4000 Public Const OFN_ShareFallThrough = 2 Public Const OFN_ShareNoWarn = 1 Public Const OFN_ShareWarn = 0 Public Const OFN_ShowHelp = &H10 Global Dialogue As OpenFileName Public strFiltre As String Public strFile As String Public strNomFile As String Public RetVal As Long Public Function OpenFile(strInitialDir As String) As String OpenFile = "" strFiltre = "Fichiers Word" & Chr$(0) & "*.doc;*txt" & Chr$(0) & _ "Fichiers Access" & Chr$(0) & "*.mdb" & Chr$(0) & _ "Fichiers Excel" & Chr$(0) & "*.xls" & Chr$(0) & _ "Tous les fichiers" & Chr$(0) & "*.*" With Dialogue .lStructSize = Len(Dialogue) .lpstrFilter = strFiltre .lpstrFile = Space(254) .nMaxFile = 255 .lpstrFileTitle = Space(254) .nMaxFileTitle = 255 .lpstrInitialDir = strInitialDir .lpstrTitle = "Recherche d'un fichier" .Flags = 6148 Or OFN_AllowMultiSelect Or OFN_LongNames Or OFN_EXPLORER End With RetVal = GetOpenFileName(Dialogue) If RetVal >= 1 Then OpenFile = Dialogue.lpstrFile Else OpenFile = "" Exit Function End If End Function
Partager