Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default GetOpenFilename - with a difference

Hi All,

Just wanted to know if there is a method to filter the list of files
shown in the dialog to only those containing certain text in the
filename?

As an example when l use the GetOpenFilename function l would like
like to display only .xls files containing TBREC-WK.

I know how to do the .xls bit but cany seem to get the next bit right.

All ideas greatfully received.

Regards

Michael Beckinsale

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 196
Default GetOpenFilename - with a difference

Hi Michale

I don't think you can do this with GetOpenFileName, but you can with
the FileDialog object:

Sub test()
Dim fname As String
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Add "Excel files (*.xls)", "*.xls", 1
.FilterIndex = 1
.Title = "Open Excel File"
.InitialFileName = "*TBREC-WK*.xls"
If .Show = True Then Workbooks.Open .SelectedItems(1)
End With
End Sub

I think this will default to whatever your current directory is (so
you may want to set that first), alternatively, if you know the exact
folder you want, then you can specify it in the InitialFileName
property eg:

..InitialFileName = "C:\MyFolder\*TBREC-WK*.xls"

I hope this helps!

Richard


On 21 Feb, 11:02, "michael.beckinsale"
wrote:
Hi All,

Just wanted to know if there is a method to filter the list of files
shown in the dialog to only those containing certain text in the
filename?

As an example when l use the GetOpenFilename function l would like
like to display only .xls files containing TBREC-WK.

I know how to do the .xls bit but cany seem to get the next bit right.

All ideas greatfully received.

Regards

Michael Beckinsale



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default GetOpenFilename - with a difference

Hi Richard,

Thanks for the info.

I will give it a try and get back to you.

Regards

Michael Beckinsale

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default GetOpenFilename - with a difference

Hi Richard,

Tried the code / idea that you offered and it works a treat.

I think l will probably use this method in preference to the
'GetOpenFilename' in many of my applications.

Again, many thanks.

Regards

Michael Beckinsale

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default GetOpenFilename - with a difference

As long as you recognize it didn't exist before xl2002 - so if your users all
have xl2002 and later, should work fine.

---
Regards,
Tom Ogilvy


"michael.beckinsale" wrote:

Hi Richard,

Tried the code / idea that you offered and it works a treat.

I think l will probably use this method in preference to the
'GetOpenFilename' in many of my applications.

Again, many thanks.

Regards

Michael Beckinsale




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default GetOpenFilename - with a difference

Hi Tom,

Thanks for the info.

I think i'm OK on this occasion but l will have to check.

I'm really glad you mentioned it.

Is there a solution / workaround for previous versions?

Regards

Michael Beckinsale

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default GetOpenFilename - with a difference

You can use the windows API:

http://www.dailydoseofexcel.com/arch...topenfilename/

see Jamie Collin's second response with a link to a post by Bob Phillips.


--
Regards,
Tom Ogilvy



"michael.beckinsale" wrote:

Hi Tom,

Thanks for the info.

I think i'm OK on this occasion but l will have to check.

I'm really glad you mentioned it.

Is there a solution / workaround for previous versions?

Regards

Michael Beckinsale


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default GetOpenFilename - with a difference

Hi Tom,

Again may thanks. It must have taken a while to track down Bob's
example and l really do appreciate it.

His example is a complex bit of coding!

I take it l can copy & paste it into my workbook, and just edit as
necessary?

Does the code have to be placed in any specific modules?

I will give it a try

Regards

Michael beckinsale


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default GetOpenFilename - with a difference

Yes, - at least large portions of it have to be in a class module (and named)
as he describes.

I took the liberty of putting it in an xls and sending it to you since it is
kind of complex and needed some cleanup for word wrap. (and Bob had the typo
on what the class name should be named.)

--
Regards,
Tom Ogilvy



"michael.beckinsale" wrote:

Hi Tom,

Again may thanks. It must have taken a while to track down Bob's
example and l really do appreciate it.

His example is a complex bit of coding!

I take it l can copy & paste it into my workbook, and just edit as
necessary?

Does the code have to be placed in any specific modules?

I will give it a try

Regards

Michael beckinsale



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
charting a difference of 2 columns' w/o adding a difference column Wab Charts and Charting in Excel 4 July 27th 05 02:37 AM
GetOpenFilename Chodu Excel Programming 1 May 17th 04 06:17 PM
GetOpenFilename Todd Htutenstine Excel Programming 2 May 13th 04 03:14 PM
GetOpenFilename Greg Bloom Excel Programming 0 February 9th 04 03:32 PM
GetOpenFilename Daniel[_4_] Excel Programming 3 July 27th 03 11:00 AM


All times are GMT +1. The time now is 08:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"