Second run of macro hangs on .show of application.filedialog object!

H

Horus

Dear All!

I am new to this forum and quite new on programming Excel VBA as well
but here goes...

I am programming a module containing a Sub that employs th
application.filedialog object to get the path to a folder from th
user.

It works fine the first time I run it after starting Excel, but it hang
when I attempt it the second time. I use the Task Manager to close Exce
and get the message that "The system cannot end this program because i
is waiting for a response from you".

I think that I understand as much as that the filedialog object belong
to the Excel application as such and I guess it somehow persists betwee
my macro runs. I also assume that somewhere in my macro I am doin
something to change its state and cause it to malfunction the secon
time around.

I could post some code, but thought that a quick fix would be if it wa
somehow possible to reset or reload the filedialog object from scratch
I have not found such a possibility and to my surprise I have not bee
able to find any one else describing this issue on this or othe
forums.

Any help would be greatly appreciated
 
G

GS

I've always found this much more consistently reliable...

Function GetDirectory$(Optional OpenAt, Optional Msg$)
Dim SH As Object

If Msg = "" Then Msg = "Please choose a folder"
Set SH = CreateObject("Shell.Application").BrowseForFolder(0, Msg,
&H40 Or &H10, OpenAt)

On Error Resume Next
GetDirectory = SH.Self.Path
On Error GoTo 0
Set SH = Nothing
End Function 'GetDirectory()

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
H

Horus

'GS[_2_ said:
;1616942']I've always found this much more consistently reliable...

Function GetDirectory$(Optional OpenAt, Optional Msg$)
Dim SH As Object

If Msg = "" Then Msg = "Please choose a folder"
Set SH = CreateObject("Shell.Application").BrowseForFolder(0, Msg,
&H40 Or &H10, OpenAt)

On Error Resume Next
GetDirectory = SH.Self.Path
On Error GoTo 0
Set SH = Nothing
End Function 'GetDirectory()

Works like a charm! How do I join your fan-list Garry
 
G

GS

'GS[_2_ said:
;1616942']I've always found this much more consistently reliable...

Function GetDirectory$(Optional OpenAt, Optional Msg$)
Dim SH As Object

If Msg = "" Then Msg = "Please choose a folder"
Set SH = CreateObject("Shell.Application").BrowseForFolder(0, Msg,
&H40 Or &H10, OpenAt)

On Error Resume Next
GetDirectory = SH.Self.Path
On Error GoTo 0
Set SH = Nothing
End Function 'GetDirectory()

Works like a charm! How do I join your fan-list Garry?

I don't know anything about a fan-list, but I do appreciate the
feedback!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top