PC Review


Reply
Thread Tools Rate Thread

Application.FileDialog .Filters.Add method not working as expected

 
 
geoff_ness
Guest
Posts: n/a
 
      27th Oct 2009
Hello

I have used the following in Excel 2007 to allow a user to select a
file:

Dim fdObj As FileDialog

Set fdObj = Application.FileDialog(msoFileDialogOpen)
With fdObj
.AllowMultiSelect = False
.Title = gsAPP_NAME
.Filters.Clear
.Filters.Add "Consolidation Reports", ".xls"
.InitialView = msoFileDialogViewDetails
If .Show = -1 Then
.Execute
End If
End With

Set fdObj = Nothing

Fairly standard I would have thought, but this breaks on the line with
the .Filters.Add method, with error message "Invalid procedure call or
argument". What am I missing here?

Cheers
Geoff
 
Reply With Quote
 
 
 
 
geoff_ness
Guest
Posts: n/a
 
      28th Oct 2009
On Oct 28, 12:52*pm, joel <joel.40q...@thecodecage.com> wrote:
> You are missing the asterisk before the ".xls"
>
> from
> ".xls"
> to
> "*.xls"
>
> --
> joel
> ------------------------------------------------------------------------
> joel's Profile:http://www.thecodecage.com/forumz/member.php?userid=229
> View this thread:http://www.thecodecage.com/forumz/sh...d.php?t=148503


D'oh!! Thanks joel
 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      28th Oct 2009
I think I'd try something like this

..Filters.Add "Consolidation Reports*" & ".xls"

"geoff_ness" wrote:

> Hello
>
> I have used the following in Excel 2007 to allow a user to select a
> file:
>
> Dim fdObj As FileDialog
>
> Set fdObj = Application.FileDialog(msoFileDialogOpen)
> With fdObj
> .AllowMultiSelect = False
> .Title = gsAPP_NAME
> .Filters.Clear
> .Filters.Add "Consolidation Reports", ".xls"
> .InitialView = msoFileDialogViewDetails
> If .Show = -1 Then
> .Execute
> End If
> End With
>
> Set fdObj = Nothing
>
> Fairly standard I would have thought, but this breaks on the line with
> the .Filters.Add method, with error message "Invalid procedure call or
> argument". What am I missing here?
>
> Cheers
> Geoff
> .
>

 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      28th Oct 2009
Hi Geoff,

Did you really get the answer you were looking for? If you did then
disregard the following.

I thought that Filters referred to the actual list of available file types
that you select from the dropdown if you open the filedialog box in the
interactive mode.

If you want all file names that start with "Consolidation Reports" then you
should set InitialFileName

..InitialFileName = "Consolidation Reports*.xls"

You can also prefix the filename with the path otherwise it uses the current
directory.


--
Regards,

OssieMac


"geoff_ness" wrote:

> Hello
>
> I have used the following in Excel 2007 to allow a user to select a
> file:
>
> Dim fdObj As FileDialog
>
> Set fdObj = Application.FileDialog(msoFileDialogOpen)
> With fdObj
> .AllowMultiSelect = False
> .Title = gsAPP_NAME
> .Filters.Clear
> .Filters.Add "Consolidation Reports", ".xls"
> .InitialView = msoFileDialogViewDetails
> If .Show = -1 Then
> .Execute
> End If
> End With
>
> Set fdObj = Nothing
>
> Fairly standard I would have thought, but this breaks on the line with
> the .Filters.Add method, with error message "Invalid procedure call or
> argument". What am I missing here?
>
> Cheers
> Geoff
> .
>

 
Reply With Quote
 
geoff_ness
Guest
Posts: n/a
 
      28th Oct 2009
Thanks Ossie
Yes I did - but thanks for the suggestion. In this instance the
filenames in question don't start with the string "Consolidation
Reports", although I can see how you and Barb both thought that from
the code I posted. Filtering on the .xls extension is sufficient to
get what's needed from this directory (which I did eventually specify
using the .InitialFileName property), as these reports will be the
only xls files in there. Here's the finished code:

Public Sub RetrieveConsolidation()
' pre: None
' post: Consolidation report workbook opened
Dim fdObj As FileDialog

InitGlobals

Set fdObj = Application.FileDialog(msoFileDialogOpen)
With fdObj
.AllowMultiSelect = False
.Title = gsAPP_NAME
.Filters.Clear
.Filters.Add "Consolidation Reports", "*.xls"
.InitialView = msoFileDialogViewDetails
.InitialFileName = gsAppDir
If .Show = -1 Then
.Execute
End If
End With

Set fdObj = Nothing

End Sub

Cheers
Geoff

On Oct 28, 3:35*pm, OssieMac <Ossie...@discussions.microsoft.com>
wrote:
> Hi Geoff,
>
> Did you really get the answer you were looking for? If you did then
> disregard the following.
>
> I thought that Filters referred to the actual list of available file types
> that you select from the dropdown if you open the filedialog box in the
> interactive mode.
>
> If you want all file names that start with "Consolidation Reports" then you
> should set InitialFileName
>
> .InitialFileName = "Consolidation Reports*.xls"
>
> You can also prefix the filename with the path otherwise it uses the current
> directory.
>
> --
> Regards,
>
> OssieMac
>
>
>
> "geoff_ness" wrote:
> > Hello

>
> > I have used the following in Excel 2007 to allow a user to select a
> > file:

>
> > Dim fdObj As FileDialog

>
> > Set fdObj = Application.FileDialog(msoFileDialogOpen)
> > With fdObj
> > * * .AllowMultiSelect = False
> > * * .Title = gsAPP_NAME
> > * * .Filters.Clear
> > * * .Filters.Add "Consolidation Reports", ".xls"
> > * * .InitialView = msoFileDialogViewDetails
> > * * If .Show = -1 Then
> > * * * * .Execute
> > * * End If
> > End With

>
> > Set fdObj = Nothing

>
> > Fairly standard I would have thought, but this breaks on the line with
> > the .Filters.Add method, with error message "Invalid procedure call or
> > argument". What am I missing here?

>
> > Cheers
> > Geoff
> > .- Hide quoted text -

>
> - Show quoted text -

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FileDialog Filters.clear eggpap Microsoft Excel Programming 1 2nd May 2008 09:57 AM
Filedialog err 438 Object doesn't support this property or method =?Utf-8?B?QXJlZiBNaWthdGk=?= Microsoft Access Form Coding 2 4th Nov 2006 01:02 PM
call __doPostBack from javascript method not working as expected SteveSu Microsoft ASP .NET 2 8th Nov 2005 07:03 AM
Application.Volatile not working as expected =?Utf-8?B?UmljaGFyZHM=?= Microsoft Excel Misc 3 3rd Feb 2005 12:20 AM
Application.FileDialog Edward Harford Microsoft Access Form Coding 1 5th Feb 2004 02:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:32 PM.