Discussion:
browseforfolder to find file
(too old to reply)
Alan Gillott
2007-02-27 02:03:50 UTC
Permalink
This code:

Set oShell = CreateObject("Shell.Application")

set oFolder = oShell.BrowseForFolder(0,"Select poem",BIF_BROWSEINCLUDEFILES
+ 1,5)


Gives This Error
the system cannot find the file specified

Any thoughts???

Works great if I select a folder, dies if I select a file. works OK in VB6,
fails in VBScript

A
Richard Mueller [MVP]
2007-02-27 04:21:07 UTC
Permalink
Post by Alan Gillott
Set oShell = CreateObject("Shell.Application")
set oFolder = oShell.BrowseForFolder(0,"Select
poem",BIF_BROWSEINCLUDEFILES + 1,5)
Gives This Error
the system cannot find the file specified
Any thoughts???
Works great if I select a folder, dies if I select a file. works OK in
VB6, fails in VBScript
First, you must assign the value &H4000 to BIF_BROWSEINCLUDEFILES. Next, the
shell application provides a wrapper for the shBrowseForFolder API. I a
believe this option allows you to view files in the folders, but does not
allow you to select files. At least, when I use the API I am not able to
select files. I had to use completely different methods to select files.
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
mayayana
2007-02-27 04:31:41 UTC
Permalink
I don't get what "+ 1,5" is, but assuming
BIF_BROWSEINCLUDEFILES is &H4000
it should work on some systems. It works on
Win98. But I don't think it works on XP and
maybe not on ME.

If you want to browse for files and have it work on
any system, you can use this:

---------------------------------------
s = ChooseFile()
MsgBox s

Function ChooseFile()
On Error Resume Next
Dim Q2, sRet
Q2 = chr(34)
ChooseFile = ""
Set IE = CreateObject("InternetExplorer.Application")
IE.visible = False
IE.Navigate("about:blank")
Do Until IE.ReadyState = 4
Loop

IE.Document.Write "<HTML><BODY><INPUT ID=" & Q2 & "Fil" & Q2 & "Type=" &
Q2 & "file" & Q2 & "></BODY></HTML>"
With IE.Document.all.Fil
.focus
.click
sRet = .value
End With
IE.Quit
Set IE = Nothing
ChooseFile = sRet
End Function
--------------------------------
Post by Alan Gillott
Set oShell = CreateObject("Shell.Application")
set oFolder = oShell.BrowseForFolder(0,"Select
poem",BIF_BROWSEINCLUDEFILES
Post by Alan Gillott
+ 1,5)
Gives This Error
the system cannot find the file specified
Any thoughts???
Works great if I select a folder, dies if I select a file. works OK in VB6,
fails in VBScript
A
unknown
2007-02-27 16:09:32 UTC
Permalink
Post by mayayana
But I don't think it works on XP and
maybe not on ME.
Yup, it doesn't work here on XP Sp2


Good Luck, Ayush.
--
Scripting Solutions Center : http://snipurl.com/Scripting_Solutions
TDM
2007-02-27 18:40:18 UTC
Permalink
Post by mayayana
I don't get what "+ 1,5" is, but assuming
BIF_BROWSEINCLUDEFILES is &H4000
it should work on some systems. It works on
Win98. But I don't think it works on XP and
maybe not on ME.
here is a function I use that works on XP, have not tested it on
anything else.

The function returns the Full path, pass in your starting point
like "C:\temp" etc.

Function browseForFile(strStartPath)
' This function returns the file name via the Browse for file box.
'
Dim objDialog
Dim iRtn

Set objDialog = CreateObject("UserAccounts.CommonDialog")

With objDialog
.Filter = "All Files|*.*"
.FilterIndex = 1
.InitialDir = strStartPath
iRtn = .ShowOpen
If iRtn = 0 Then
browseForFile = ""
Else
browseForFile = .FileName
End If
End With

End Function


TDM
mayayana
2007-02-27 19:19:07 UTC
Permalink
Post by TDM
here is a function I use that works on XP, have not tested it on
anything else.
That's XP only.
TDM
2007-02-27 21:23:42 UTC
Permalink
Post by mayayana
Post by TDM
here is a function I use that works on XP, have not tested it on
anything else.
That's XP only.
Thanks for the info.


TDM

Alexander Mueller
2007-02-27 09:50:06 UTC
Permalink
Post by Alan Gillott
Set oShell = CreateObject("Shell.Application")
set oFolder = oShell.BrowseForFolder(0,"Select poem",BIF_BROWSEINCLUDEFILES
+ 1,5)
Gives This Error
the system cannot find the file specified
Any thoughts???
BIF_BROWSEINCLUDEFILES should be defined as 16384 / &H4000

Note that, browsing for files is damaged on the XP-version of
shell32.dll, raising the error you quoted, a known bug.


MfG,
Alex
Loading...