FolderPicker dialog box

M

MD

Using the FolderPicker (along with Microsoft Scripting Runtime), how do I
open the dialog box in a specific folder (say c:\temp)

Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.Show
' ???? instruction for the dialog box to open in c:\temp
End With

Regards

Michel
 
D

Dave Peterson

How about:

Option Explicit
Sub testme01()
Dim fd As FileDialog
Dim curFolder As String
Dim newFolder As String

newFolder = "C:\temp"

curFolder = CurDir

ChDir newFolder
ChDrive newFolder

Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.Show
End With

ChDir curFolder
ChDrive curFolder
End Sub
 
M

MD

This is strange.... I used your exemple... and It worked(only one time) I
modified the value of "newFolder" to D:\temp and it still gave me C:\temp
?? I close the workbook (but kept EXCEL open)... same thing...... I closed
EXCEL all together and it now worked.

It seems that changing the value of newFolder is tricky. Say you want to
add "IF" this then newfolder X value "IF" that then newfolderYvalue

Option Explicit
Sub testme01()
Dim fd As FileDialog
Dim curFolder As String
Dim newFolder As String

newFolder = "C:\temp"

curFolder = CurDir

ChDir newFolder
ChDrive newFolder

Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.Show
End With

ChDir curFolder
ChDrive curFolder
End Sub...????
 
W

w0rm

Try following:

Set fd = Application.FileDialog(msoFileDialogFolderPicker)
fd.InitialFileName = "c:\temp"
With fd
.Show
End With



Jan
 
D

Dave Peterson

In win98/xl2002, I had to use:
fd.InitialFileName = "c:\temp\"

And to keep it from making it the current directory:

Option Explicit
Sub testme01()
Dim fd As FileDialog
Dim curFolder As String
Dim newFolder As String

newFolder = "C:\temp\"

curFolder = CurDir

ChDir newFolder
ChDrive newFolder

Set fd = Application.FileDialog(msoFileDialogFolderPicker)

With fd
.InitialFileName = newFolder
.Show
End With

ChDir curFolder
ChDrive curFolder
End Sub

(Thanks for posting the solution, w0rm.)
 

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