PDA

View Full Version : Solved: file Dialog errors



Trevor
03-27-2008, 04:47 PM
I am trying to open a file dialog and have the reference for MSO 11
and using code :

Dim xx
Debug.Print CurDir
xx = Application.FileDialog(msoFileDialogFolderPicker).Show
Debug.Print CurDir

End Sub

and I get an error on click, that says find dialog 'of object' faild

DarkSprout
03-28-2008, 01:57 AM
Have a look at:=
http://www.vbaexpress.com/forum/showthread.php?t=17114

Trevor
03-28-2008, 02:16 PM
Thanks, Darksprout, I am trying to use the file dialog so that the user can select a folder that files will automaticly be placed into, and this code workes for items, I tried changeing the class .selectedItems to .Selected folders
and for Each Selectedfolder In .Selected Folders,
but this produces an error I know its a class proporties(which I am not always good at , so here is the code I'm usinge (it doen't reflect the changes I made a above though, at the bottom of the code where it msgbox = path selected I will have the path also populate a textbox that will then update a table and the value will be pulled from the table in other modules.

'Declare a variable as a FileDialog object.
Dim fd As FileDialog

'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)

'Declare a variable to contain the path
'of each selected item. Even though the path is aString,
'the variable must be a Variant because For Each...Next
'routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant

'Use a With...End With block to reference the FileDialog object.
With fd

'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the button.
If .Show = -1 Then

'Step through each string in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems

'vrtSelectedItem is a string that contains the path of each selected item.
'You can use any file I/O functions that you want to work with this path.
'This example displays the path in a message box.
MsgBox "The path is: " & vrtSelectedItem

Next vrtSelectedItem
'The user pressed Cancel.
Else
End If
End With

'Set the object variable to nothing.
Set fd = Nothing

End Sub

Trevor
03-28-2008, 04:39 PM
I solved it, check this out

http://vbaexpress.com/kb/getapprovalarticle.php?kb_id=1002