Ouvrir fichier excel avec vba
salut a tous,
j'essaie de faire un programme pour pouvoir ouvrir n'importe quel type de fichiers à travers un code vba.
mon code est le suivant
Code:
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
| Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
String, ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal lpszDir As String, ByVal fsShowCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Const SW_SHOWNORMAL = 1
Function StartDoc(DocName As String) As Long
Dim Scr_hDC As Long
Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _
"", "C:\", SW_SHOWNORMAL)
End Function
Sub TESTH()
Dim r As Long
Dim ledoc As String
Dim chemin As String
chemin = Range("ai:aj").Find(what:=Range("f6")).Offset(0, 1).Value
ledoc = chemin
r = StartDoc(ledoc)
End Sub |
cependant sa marche pour TOUT type de fichiers ... office, internet, photo, text, explorateur ...
mais pour les fichiers excel, sa plante ! sa ne sort pas une msgbox d'erreur, mais sa mouline a fond sans s'en sortir ..
en mode pas a pas, apriori je detecte le bug a la ligne
Code:
1 2
| StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _
"", "C:\", SW_SHOWNORMAL) |
si vous avez une idée ..
merci d'avance