In Excel, I have used this;
strFilePath = Application.GetOpenFilename("Excel Files (*.xls),*.xls")
or....
Function File_2_Open() As String
Dim strVar As Variant
On Error Resume Next
strVar = Application.GetOpenFilename("Excel Files (*.xls),*.xls")
Workbooks.Open strVar
' deal with it... your code here...
File_2_Open = strVar
End Function
This .GetOpenFilename results in a error;
Compile error: Method or data member not found
or...
Dim strFilePath As String
Dim objWord As Word.Document
Dim V As Variant
On Error Resume Next
'Allow the user to select the Word document
With Application.FileDialog(msoFileDialogOpen)
.Title = "Select Word Document"
.AllowMultiSelect = False
.Filters.Add "Word Documents", "*.docx; *.doc", 1
.Filters.Add "All Files", "*.*", 2
'Show the dialog and if returned True, use the selected file
If .Show = True Then 'The user clicked "OK"
strFilePath = .SelectedItems(1)
The last code snippet returns an error from msoFileDialogOpen; Variable not
defined?
So, neither of the examples above will work. What method can I use here to
return the file path?
Thank you for any help!
Regards Jan T.
Ken Snell
http://www.accessmvp.com/KDSnell/
"Jan T." <noreply> wrote in message
news:edJEHkSd...@TK2MSFTNGP05.phx.gbl...
Regards
Jan T.
"Ken Snell" <kthsne...@ncoomcastt.renaetl> skrev i melding
news:uYCkYJWd...@TK2MSFTNGP05.phx.gbl...
Dim f As FileDialog
Set f = Application.FileDialog(msoFileDialogFilePicker)
f.Show
MsgBox "file choose was " & f.SelectedItems(1)
You can late bind if you wish:
above needs: Microsoft Object 11.0 Object library
If you don't want the above reference, then the following
code will work without any references:
Dim f As Object
Set f = Application.FileDialog(3)
f.AllowMultiSelect = True
f.Show
MsgBox "file choosen = " & f.SelectedItems.Count
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOO...@msn.com
> You can also consider:
>
> Dim f As FileDialog
> Set f = Application.FileDialog(msoFileDialogFilePicker)
> f.Show
> MsgBox "file choose was " & f.SelectedItems(1)
>
> You can late bind if you wish:
>
> above needs: Microsoft Object 11.0 Object library
>
> If you don't want the above reference, then the following
> code will work without any references:
>
>
> Dim f As Object
> Set f = Application.FileDialog(3)
> f.AllowMultiSelect = True
> f.Show
>
> MsgBox "file choosen = " & f.SelectedItems.Count
I fail to perceive the utility in declaring a weakly-typed object
variable here as opposed to just using a WITH block, i.e.:
With Application.FileDialog(3)
.AllowMultiSelect = True
.Show
MsgBox "file choosen = " & .SelectedItems.Count
End With
I've never used the FileDialog object, so maybe I'm missing
something here.
--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/