Bonjour,
J'aimerai par une macro enregistrer dans un variable le nom d'un classeur
choisi à partir d'une fenètre de type "ouvrir" mais sans ouvrir le classeur
en question.
Merci pour votre aide.
Romain
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Nicolas B.
Salut Rom1,
Un exemple utilisant FileDialog :
Sub Toto() Dim ofd As FileDialog Set ofd = Application.FileDialog(msoFileDialogOpen) ofd.Show MsgBox ofd.SelectedItems(1) End Sub
A+ Nicolas B.
Bonjour, J'aimerai par une macro enregistrer dans un variable le nom d'un classeur choisi à partir d'une fenètre de type "ouvrir" mais sans ouvrir le classeur en question. Merci pour votre aide. Romain
Salut Rom1,
Un exemple utilisant FileDialog :
Sub Toto()
Dim ofd As FileDialog
Set ofd = Application.FileDialog(msoFileDialogOpen)
ofd.Show
MsgBox ofd.SelectedItems(1)
End Sub
A+
Nicolas B.
Bonjour,
J'aimerai par une macro enregistrer dans un variable le nom d'un classeur
choisi à partir d'une fenètre de type "ouvrir" mais sans ouvrir le classeur
en question.
Merci pour votre aide.
Romain
Sub Toto() Dim ofd As FileDialog Set ofd = Application.FileDialog(msoFileDialogOpen) ofd.Show MsgBox ofd.SelectedItems(1) End Sub
A+ Nicolas B.
Bonjour, J'aimerai par une macro enregistrer dans un variable le nom d'un classeur choisi à partir d'une fenètre de type "ouvrir" mais sans ouvrir le classeur en question. Merci pour votre aide. Romain
Xav
Bonjour Rom1
Si tu as une version Excel 2000 ou antérieure, FileDialog n'existe pas.
tu peux créer la fonction suivante dans un module.
Tu appelles ensuite la fonction avec GetDirectory
Public Type BROWSEINFO hOwner As Long pidlRoot As Long pszDisplayName As String lpszTitle As String ulFlags As Long lpfn As Long lParam As Long iImage As Long End Type
'32-bit API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" _ Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long Declare Function SHBrowseForFolder Lib "shell32.dll" _ Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Function GetDirectory(indice As Integer, Optional msg) As String Dim bInfo As BROWSEINFO Dim path As String Dim r As Long, x As Long, pos As Integer
bInfo.pidlRoot = 0&
If IsMissing(msg) Then bInfo.lpszTitle = "Select a folder." Else bInfo.lpszTitle = msg End If
bInfo.ulFlags = &H1
x = SHBrowseForFolder(bInfo) path = VBA.Strings.Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path) If r Then pos = VBA.Strings.InStr(path, VBA.Strings.Chr$(0)) GetDirectory = VBA.Strings.Left(path, pos - 1) Else GetDirectory = "" End If End Function
-- Cordialement
@+ Xav "Rom1" a écrit dans le message de news:
Bonjour, J'aimerai par une macro enregistrer dans un variable le nom d'un classeur choisi à partir d'une fenètre de type "ouvrir" mais sans ouvrir le classeur
en question. Merci pour votre aide. Romain
Bonjour Rom1
Si tu as une version Excel 2000 ou antérieure, FileDialog n'existe pas.
tu peux créer la fonction suivante dans un module.
Tu appelles ensuite la fonction avec GetDirectory
Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
'32-bit API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String)
As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Function GetDirectory(indice As Integer, Optional msg) As String
Dim bInfo As BROWSEINFO
Dim path As String
Dim r As Long, x As Long, pos As Integer
bInfo.pidlRoot = 0&
If IsMissing(msg) Then
bInfo.lpszTitle = "Select a folder."
Else
bInfo.lpszTitle = msg
End If
bInfo.ulFlags = &H1
x = SHBrowseForFolder(bInfo)
path = VBA.Strings.Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = VBA.Strings.InStr(path, VBA.Strings.Chr$(0))
GetDirectory = VBA.Strings.Left(path, pos - 1)
Else
GetDirectory = ""
End If
End Function
--
Cordialement
@+
Xav
"Rom1" <Rom1@discussions.microsoft.com> a écrit dans le message de
news:7372FE02-15FB-4551-9776-8CF3650EF77B@microsoft.com...
Bonjour,
J'aimerai par une macro enregistrer dans un variable le nom d'un classeur
choisi à partir d'une fenètre de type "ouvrir" mais sans ouvrir le
classeur
Si tu as une version Excel 2000 ou antérieure, FileDialog n'existe pas.
tu peux créer la fonction suivante dans un module.
Tu appelles ensuite la fonction avec GetDirectory
Public Type BROWSEINFO hOwner As Long pidlRoot As Long pszDisplayName As String lpszTitle As String ulFlags As Long lpfn As Long lParam As Long iImage As Long End Type
'32-bit API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" _ Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long Declare Function SHBrowseForFolder Lib "shell32.dll" _ Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Function GetDirectory(indice As Integer, Optional msg) As String Dim bInfo As BROWSEINFO Dim path As String Dim r As Long, x As Long, pos As Integer
bInfo.pidlRoot = 0&
If IsMissing(msg) Then bInfo.lpszTitle = "Select a folder." Else bInfo.lpszTitle = msg End If
bInfo.ulFlags = &H1
x = SHBrowseForFolder(bInfo) path = VBA.Strings.Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path) If r Then pos = VBA.Strings.InStr(path, VBA.Strings.Chr$(0)) GetDirectory = VBA.Strings.Left(path, pos - 1) Else GetDirectory = "" End If End Function
-- Cordialement
@+ Xav "Rom1" a écrit dans le message de news:
Bonjour, J'aimerai par une macro enregistrer dans un variable le nom d'un classeur choisi à partir d'une fenètre de type "ouvrir" mais sans ouvrir le classeur