Open a folder in VBA

aryan_hr

Board Regular
Joined
Feb 19, 2002
Messages
222
Hi,
It is my program that opens a folder " My_Folder" in VBA.
But if there is an error, windows exploere showes the error not my program. why??
best wishes
-------------------------------------
Private Sub Show_Input()
Dim My_Folder As String
My_Folder = "A:ddd"
On Error GoTo Error_Show_Input:

Shell "c:windowsexplorer " + My_Folder, 1
On Error GoTo 0
Exit Sub
Error_Show_Input:
MsgBox "Progran can not open this folder." + Chr(13) + Chr(10) + "[" + Error(Err) + "]", vbOKOnly, "Error"
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329
Hi aryan_hr,

I'm no expert but I believe that when you 'shell out' to another program, eg explorer, control passes to that program. Therefore, your error-trapping routine will not catch any errors arising in explorer.

What exactly are you trying to achieve? Could it be done with "Application.GetOpenFilename"? Or try the following link for bringing-up an open folder dialog box in VBA:

http://www.erlandsendata.no/english/vba/folders/selectfolder.htm

HTH
 

aryan_hr

Board Regular
Joined
Feb 19, 2002
Messages
222
Hi Richie,
thanks, you are right about error-trapping routine.
But I exactly want to open a folder in VB or VBA.
How can I do it in my program and catch any errors arising ?
Also I did it by "Shell" and before running the "Shell" commend, I checked the folder and trapped the error.
But I think there is a simple way for this work.
any help?
best wishes
 

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329
Hi,

Did you check the link above? I believe that does what you are looking for?


_________________<font color="blue"> «««<font color="red">¤<font color="blue"><font size=+1>Richie</font><font color="red">¤<font color="blue"> »»»</font>

caffeine_sample.gif
</gif>
This message was edited by Richie(UK) on 2002-09-23 03:50
 

aryan_hr

Board Regular
Joined
Feb 19, 2002
Messages
222

ADVERTISEMENT

Hi,
yeah... I had seen it before. That program only selects a folder and not open it.
I only want to open a folder.
any help?
 

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329
Hi,

What are you trying to achieve?

That is, what are you going to do once you have opened the folder? Are you saving, loading, listing or what?
 

aryan_hr

Board Regular
Joined
Feb 19, 2002
Messages
222
Hi,
thanks for your reply.
I have written a program that creates a new folder including some files. Now after finishing my program, I want to open this folder and take a look in.
any help?
 

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329
Hi,

How about using "Dir" or "FileSearch" to provide the information that you want?

Or, possibly, "Application.GetOpenFileName" if you really want a browser type view.

HTH
 

Forum statistics

Threads
1,144,508
Messages
5,724,767
Members
422,577
Latest member
kayth891

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top