From: Kryten on
Thank you for the advice Mayayana!

I have actually gone ahead and used the
jsware dialog and I'm really happy with it and
grateful for the pointer to it.

I'm actually scripting for SecureCRT and this
is giving me everything I need. When the customer
upgrades to W7 later in the year...well, I'll rethink it
then!

Much appreciated!

Stuart
From: mayayana on
I just did an interesting test. Using the code that
I posted for calling an IE dialogue, I tried it on
XP (NTFS formatting, running as admin) with IE8.
If I load the script from an HTA it works fine. (I
load an external .vbs file into the HTA with
<SCRIPT SRC=.....)

If I run the code directly from a script under WSH
it also works, but it returns a dummy path. No matter
what file I select, from any drive, I get something like:

C:\fakepath\text1.txt

The file name is right but the path is false. I found
info. about it here:
http://acidmartin.wordpress.com/2009/06/09/the-mystery-of-cfakepath-unveiled
/

According to that page it will work if your Local
Zone is trusted, but starting with XP SP2 the Local
Zone uses the "Lockdown" settings, putting it into
the equivalent of the Restricted Zone. You can change
the Local Zone security settings. I don't know whether
that equates to putting it into the Trusted Zone.

Also according to the link above, this new security
took effect with IE8. I don't have IE7 handy to test,
but I would think that if you want to be sure about
whether it will work on different machines then you'll
need to test both IE7 and IE8, under both normal
XP security and Vista/7 extreme security.

I guess the good news is that if you can call it
from an HTA you should be OK on all systems.


From: Kryten on
Hi Mayayana,

Yep, I'm getting the fakepath syndrome too!

Thanks for the link explaining the backstory, I think
that might have driven me insane trying to figure
that one out otherwise.

I'm playing around with :-


Set ie = CreateObject("InternetExplorer.Application")
ie.Offline = True
IE.navigate "about:blank"

Do
WScript.Sleep 100
Loop While ie.Busy

szHTMLBody = "<input type=file name=file>"
ie.document.Body.InnerHTML = szHTMLBody
ie.width = 0
ie.height = 0
ie.Document.All("file").Click
Set chosen = ie.Document.All("file").Value
if chosen = "" Then
MsgBox "User Cancelled."
Else
MsgBox chosen
end If
ie.quit


It's actually working rather well.

Thanks again,
Stuart


From: mayayana on
>
> I'm playing around with :-
>

So far I've only tried your version on 98. There's
an error due to the use of Set chosen, since
ie.Document.All("file").Value is not an object.

>
> Set ie = CreateObject("InternetExplorer.Application")
> ie.Offline = True
> IE.navigate "about:blank"
>
> Do
> WScript.Sleep 100
> Loop While ie.Busy
>
> szHTMLBody = "<input type=file name=file>"
> ie.document.Body.InnerHTML = szHTMLBody
> ie.width = 0
> ie.height = 0
> ie.Document.All("file").Click
> Set chosen = ie.Document.All("file").Value
> if chosen = "" Then
> MsgBox "User Cancelled."
> Else
> MsgBox chosen
> end If
> ie.quit
>
>
> It's actually working rather well.
>
> Thanks again,
> Stuart
>
>


From: jeng02 on
Same here. I am programming in Office 2010 64-bit VBA on Windows 7 64-bit.
I can see individual files but when I select them it errors. It does not
error when I select folders or libraries. Error message is: Method
BrowseForFolder of object IShellDispatch5 failed.
Here is my code:

Sub testopen()
Dim objShell As Object
Dim strPath As String
Dim objFile
Set objShell = CreateObject("Shell.Application")
'Shows dialog but errors when you select a file:
Set objFile = objShell.BrowseForFolder(0, "Choose a file:", &H4000)
strPath = objFile.Title '& vbCrLf & objFile.self.Path
MsgBox strPath
Set objFile = Nothing
Set objShell = Nothing
End Sub

"Kryten" wrote:

> Thanks to everyone who replied.
>
> I have issues with the browseforfolder method. I had
> experimented with it before actually and was able to get
> it to expose files, OK but it always emits an error
> after selecting one of them. Never able to properly
> update the OpenfileDialog.Filename property.
>
> The IE method, for me runs but does not result
> in a filebrowser. Deconstructing the code I can
> certainly get the IE about:blank to show but the
> underlying functionality isn't there. Maybe because
> I'm using W7/IE7? Not sure.
>
> The jsware stuff looked really promising until I
> got the "Windows Vista is not supported exception".
> Looking around the jsware site it looks like I may
> be out of luck using these controls in Vista and W7 ;-)
>
> This may not be too much of a problem right now
> as the desktops I'm developing the script for all
> run XP/SP2 and will do till the end of this year.
>
> My scripting language of choice is actually Powershell,
> where thanks to applications like ASE and PrimalForms
> it's trivial to create Windows Forms Applications.
>
> It also makes instantiating .NET objects easy too.
> Such as $browse = new-object system.windows.forms.openfiledialog
>
> Any ideas, or boilerplate code for using that .NET object in
> VBScript ( Once it gets > 100 lines I lose interest though! ).
>
> Thanks again,
> Stuart
>