Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

ouvrir une boite de dialogue pour choisir un fichier

3 réponses
Avatar
michel_bdx
j'ai un bouton qui ouvre une boite de dialogue pour choisir un fichier
malheureusement ca fonctionne pas j'ai une erreur et pourtant mon appli deja
sur des postes divers XP W2K win98 mais pas sur un portable qui a un SE xp

merci pour votre aide
michel

3 réponses

Avatar
Philippe T [MS]
Bonjour,

<<<
'***************************************************************************
***
' This script demonstrates the use of the functin "BrowseForFolder." The
' function is self-contained and can be cut and pasted in any VBScript
script.
'
' Written by Seán Hennessy September 21
1998
'***************************************************************************
***


Option Explicit

Dim strPath
strPath = BrowseForFolder("Choose a folder")

If IsNull(strPath) Then
MsgBox "Invalid Folder Selection"
Else
MsgBox strPath
End If

'***************************************************************************
***
' This function displays the "Browse For Folder" dialog and returns a string
' with the UNC of the chosen folder. If an invalid folder is selected (such
as
' "My Computer"), then a null string is returned. It's only argument is the
' string for the prompt that appears beneath the title strip.
'***************************************************************************
***

Function BrowseForFolder(strPrompt)
On Error Resume Next
Dim objShell, objFolder, intColonPos, objWshShell
Set objShell = WScript.CreateObject("Shell.Application")
Set objWshShell = CreateObject("WScript.Shell")

'*********************************************************************
' I am unsure of the exact meanings of the hex values here. The first
' one is the handle of the current window and so far as I can tell is
' irrelevant in this case. The second one is the flags property of the
' dialog, and controls some features of its behaviour. 1 seems to
' force some form of validation, so that the OK button is greyed out
' if an invalid folder is selected. I would like to find some
' documentation on this.
'*********************************************************************

Set objFolder = objShell.BrowseForFolder(&H0&, strPrompt, &h1&)

BrowseForFolder = objFolder.ParentFolder.ParseName(objFolder.Title).Path

'*********************************************************************
' Now handle any errors. I have defined only two special cases;
' (1) The selected folder is the desktop at the root of the tree
' (2) The selected folder is a drive.
' In all other cases return Null.
'*********************************************************************

If Err.Number <> 0 Then
BrowseForFolder = Null 'will be null of no special case applies

If objFolder.Title = "Desktop" Then
BrowseForFolder = objWshShell.SpecialFolders("Desktop")
End If

'If selected folder is a drive, it will have a colon e.g. C:

intColonPos = InStr(objFolder.Title, ":")

If intColonPos > 0 Then
BrowseForFolder = Mid(objFolder.Title, intColonPos - 1, 2) & ""
End If
End If
End Function





Phil.
________________________________________________________
Philippe TROTIN http://blogs.msdn.com/ptrotin
Microsoft Services France http://www.microsoft.com/france

"michel_bdx" wrote in message
news:
j'ai un bouton qui ouvre une boite de dialogue pour choisir un fichier
malheureusement ca fonctionne pas j'ai une erreur et pourtant mon appli
deja

sur des postes divers XP W2K win98 mais pas sur un portable qui a un SE xp

merci pour votre aide
michel




Avatar
bjf
Bonjour,
j'ai voulu testé cette fonction mais j'ai le message
d'erreur "variable non définie" sur la ligne de code
suivante:
Set objShell = WScript.CreateObject("Shell.Application")
Manque-t-il une référence ? si oui, laquelle ?
Merci d'avance.
A+


-----Message d'origine-----
Bonjour,

<<<
'*********************************************************
******************

***
' This script demonstrates the use of the
functin "BrowseForFolder." The

' function is self-contained and can be cut and pasted in
any VBScript

script.
'
' Written by Seán
Hennessy September 21

1998
'*********************************************************
******************

***


Option Explicit

Dim strPath
strPath = BrowseForFolder("Choose a folder")

If IsNull(strPath) Then
MsgBox "Invalid Folder Selection"
Else
MsgBox strPath
End If

'*********************************************************
******************

***
' This function displays the "Browse For Folder" dialog
and returns a string

' with the UNC of the chosen folder. If an invalid folder
is selected (such

as
' "My Computer"), then a null string is returned. It's
only argument is the

' string for the prompt that appears beneath the title
strip.

'*********************************************************
******************

***

Function BrowseForFolder(strPrompt)
On Error Resume Next
Dim objShell, objFolder, intColonPos, objWshShell
Set objShell = WScript.CreateObject("Shell.Application")
Set objWshShell = CreateObject("WScript.Shell")

'********************************************************
*************

' I am unsure of the exact meanings of the hex values
here. The first

' one is the handle of the current window and so far as
I can tell is

' irrelevant in this case. The second one is the flags
property of the

' dialog, and controls some features of its behaviour. 1
seems to

' force some form of validation, so that the OK button
is greyed out

' if an invalid folder is selected. I would like to find
some

' documentation on this.
'********************************************************
*************


Set objFolder = objShell.BrowseForFolder(&H0&,
strPrompt, &h1&)


BrowseForFolder = objFolder.ParentFolder.ParseName
(objFolder.Title).Path


'********************************************************
*************

' Now handle any errors. I have defined only two special
cases;

' (1) The selected folder is the desktop at the root of
the tree

' (2) The selected folder is a drive.
' In all other cases return Null.
'********************************************************
*************


If Err.Number <> 0 Then
BrowseForFolder = Null 'will be null of no special case
applies


If objFolder.Title = "Desktop" Then
BrowseForFolder = objWshShell.SpecialFolders("Desktop")
End If

'If selected folder is a drive, it will have a colon
e.g. C:


intColonPos = InStr(objFolder.Title, ":")

If intColonPos > 0 Then
BrowseForFolder = Mid(objFolder.Title, intColonPos -
1, 2) & ""

End If
End If
End Function





Phil.
________________________________________________________
Philippe TROTIN
http://blogs.msdn.com/ptrotin

Microsoft Services France
http://www.microsoft.com/france


"michel_bdx" wrote
in message

news:
j'ai un bouton qui ouvre une boite de dialogue pour
choisir un fichier


malheureusement ca fonctionne pas j'ai une erreur et
pourtant mon appli


deja
sur des postes divers XP W2K win98 mais pas sur un
portable qui a un SE xp



merci pour votre aide
michel



.






Avatar
Philippe T [MS]
Bonjour,

Vous pouvez soit supprimer la clause : Option Explicit qui force la
définition des variables, soit ajouter un : "Dim objShell "

Phil.
________________________________________________________
Philippe TROTIN http://blogs.msdn.com/ptrotin
Microsoft Services France http://www.microsoft.com/france

"bjf" wrote in message
news:046b01c50a99$73319330$
Bonjour,
j'ai voulu testé cette fonction mais j'ai le message
d'erreur "variable non définie" sur la ligne de code
suivante:
Set objShell = WScript.CreateObject("Shell.Application")
Manque-t-il une référence ? si oui, laquelle ?
Merci d'avance.
A+


-----Message d'origine-----
Bonjour,

<<<
'*********************************************************
******************

***
' This script demonstrates the use of the
functin "BrowseForFolder." The

' function is self-contained and can be cut and pasted in
any VBScript

script.
'
' Written by Seán
Hennessy September 21

1998
'*********************************************************
******************

***


Option Explicit

Dim strPath
strPath = BrowseForFolder("Choose a folder")

If IsNull(strPath) Then
MsgBox "Invalid Folder Selection"
Else
MsgBox strPath
End If

'*********************************************************
******************

***
' This function displays the "Browse For Folder" dialog
and returns a string

' with the UNC of the chosen folder. If an invalid folder
is selected (such

as
' "My Computer"), then a null string is returned. It's
only argument is the

' string for the prompt that appears beneath the title
strip.

'*********************************************************
******************

***

Function BrowseForFolder(strPrompt)
On Error Resume Next
Dim objShell, objFolder, intColonPos, objWshShell
Set objShell = WScript.CreateObject("Shell.Application")
Set objWshShell = CreateObject("WScript.Shell")

'********************************************************
*************

' I am unsure of the exact meanings of the hex values
here. The first

' one is the handle of the current window and so far as
I can tell is

' irrelevant in this case. The second one is the flags
property of the

' dialog, and controls some features of its behaviour. 1
seems to

' force some form of validation, so that the OK button
is greyed out

' if an invalid folder is selected. I would like to find
some

' documentation on this.
'********************************************************
*************


Set objFolder = objShell.BrowseForFolder(&H0&,
strPrompt, &h1&)


BrowseForFolder = objFolder.ParentFolder.ParseName
(objFolder.Title).Path


'********************************************************
*************

' Now handle any errors. I have defined only two special
cases;

' (1) The selected folder is the desktop at the root of
the tree

' (2) The selected folder is a drive.
' In all other cases return Null.
'********************************************************
*************


If Err.Number <> 0 Then
BrowseForFolder = Null 'will be null of no special case
applies


If objFolder.Title = "Desktop" Then
BrowseForFolder = objWshShell.SpecialFolders("Desktop")
End If

'If selected folder is a drive, it will have a colon
e.g. C:


intColonPos = InStr(objFolder.Title, ":")

If intColonPos > 0 Then
BrowseForFolder = Mid(objFolder.Title, intColonPos -
1, 2) & ""

End If
End If
End Function





Phil.
________________________________________________________
Philippe TROTIN
http://blogs.msdn.com/ptrotin

Microsoft Services France
http://www.microsoft.com/france


"michel_bdx" wrote
in message

news:
j'ai un bouton qui ouvre une boite de dialogue pour
choisir un fichier


malheureusement ca fonctionne pas j'ai une erreur et
pourtant mon appli


deja
sur des postes divers XP W2K win98 mais pas sur un
portable qui a un SE xp



merci pour votre aide
michel



.