VB Shell et espaces dans les noms de fichiers - Erreur si espaces dans FilePath

Bonjour,
Je cherche comment ouvrir un fichier avec la fonction Shell.
Si dans le nom du fichier il n’y a pas d’espace cela fonctionne super.
Mais dès qu’il y a une ou plusieurs espaces cela ne fonctionne plus du tout.
Merci pour votre aide.

Exemple simplifié de mon code :

Sub Main()
Dim ApplicationPath As String = "C:\Program files\Microsoft Office\Office11\Excel.EXE "
Dim FilePath As String = "D:\Mes documents\Courses Janvier.xls"
Try
Shell(ApplicationPath & FilePath, vbMaximizedFocus)
Catch
MsgBox(Err.Description)
End Try
End Sub


Private Declare Function GetShortPathName Lib "kernel32" _
                Alias "GetShortPathNameA" _
                (ByVal lpszLongPath As String, _
                ByVal lpszShortPath As String, _
                ByVal lBuffer As Long) As Long

Function GetShortName(LongPath As String) As String
Dim LenShortName As Long
Dim buffer As String * 1000

    LenShortName = GetShortPathName(LongPath, _
                          buffer, Len(LongPath))
    If LenShortName Then
        GetShortName = Left$(buffer, LenShortName)
    End If

End Function
'------------

Source : http://accessvbafaq.mvps.org/item.asp?pagina=47

Je te laisse le soin de faire le reste :wink:

Merci KarlKox, c’est une super bonne idée.
Je l’ai adapté pour .net et ça marche super. :clap:

Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" _
(ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, _
ByVal lBuffer As Long) As Long

Function GetShortName(ByVal LongPath As String) As String
    Dim LenShortName As Long
    Dim buffer As String
    buffer = Space(256)
    LenShortName = GetShortPathName(LongPath, buffer, LongPath.Length)
    GetShortName = buffer
End Function