FileOpen Filtering
Ivan F Moala
Can Do
Goto Guest book sign in page [Home]
Thanks for visiting my site lucky visitor:
Copyright © 2002. XcelFiles. All Rights Reserved Ivan F Moala
Tell a friend about this page
  
CommonDialogRWDescription 
Property _Action As IntegerRead Only(undocumented)iAction
Property Action As IntegerRead OnlyReturns/sets the type of dialog box to be displayed.lAPIReturn
Property CancelError As BooleanRead/WriteIndicates whether an error is generated when the user chooses the Cancel button.bCancelError
Property Color As LongRead/WriteReturns/sets the selected color.lColor
Property Copies As IntegerRead/WriteReturns/sets a value that determines the number of copies to be printed.lCopies
Property DefaultExt As StringRead/WriteReturns/sets the default filename extension for the dialog box.sDefaultExt
Property DialogTitle As StringRead/WriteSets the string displayed in the title bar of the dialog box.sDialogTitle
Property FileName As StringRead/WriteReturns/sets the path and filename of a selected file.sFileName
Property Filter As StringRead/WriteReturns/sets the filters that are displayed in the Type list box of a dialog box.sFilter
Property FilterIndex As IntegerRead/WriteReturns/sets a default filter for an Open or Save As dialog box.iFilterIndex
Property Flags As LongRead/WriteSets the options for a dialog box.lFlags
Property FontBold As BooleanRead/WriteReturns/sets bold font styles.bFontBold
Property FontItalic As BooleanRead/WriteReturns/sets italic font styles.bFontItalic
Property FontName As StringRead/WriteSpecifies the name of the font that appears in each row for the given level.sFontName
Property FontSize As SingleRead/WriteSpecifies the size (in points) of the font that appears in each row for the given level.lFontSize
Property FontStrikeThru As BooleanRead/WriteReturns/sets strikethrough font styles.bFontStrikethru
Property FontUnderLine As BooleanRead/WriteReturns/sets underline font styles.bFontUnderline
Property FromPage As IntegerRead/WriteReturns/sets the value for the first page to be printed.lFromPage
Property HelpCommand As IntegerRead/WriteReturns/sets the type of online Help requested.lHelpCommand
Property HelpContext As LongRead/WriteReturns/sets the context ID of the requested Help topic.sHelpContext
Property HelpFile As StringRead/WriteReturns/sets the name of the Help file associated with the project.sHelpFile
Property HelpKey As StringRead/WriteReturns/sets the keyword that identifies the requested Help topic.sHelpKey
Property InitDir As StringRead/WriteReturns/sets the initial file directory.sInitDir
Property Max As IntegerRead/WriteReturns/sets the maximum font size (Font dialog) or print range (Print dialog).lMax
Property MaxFileSize As IntegerRead/WriteReturns/sets the maximum size of the filename opened using the CommonDialog control.lMaxFileSize
Property Min As IntegerRead/WriteSets the smallest allowable font size (Font dialog) or print range (Print dialog).lMin
Property PrinterDefault As BooleanRead/WriteDetermines if user selections in the Print dialog box are used to change the default printer settings.iPrinterDefault
Property ToPage As IntegerRead/WriteReturns/sets the value for the first page to be printed.lToPage
Google
Search WWW Search My Site!

Filtering Files using the comdlg32.dll

(Click here If you wish to Skip the descriptive text and goto the code)

What is Comdlg32.Dll

The Win32® Common Dialog API functions are located in COMDLG32.DLL, which must be in the
Windows system directory for the dialog interface to function.

The Common Dialog functions provide a standard set of Windows dialog boxes for operations such as
opening, saving, and printing files, or selecting colors and fonts. The class creates objects that, with the
exception of an object instantiation line, are code-compatible with Visual Basic's Common Dialog control.
= COMDLG32.OCX.

Programs using the Visual Basic Common Dialog control require that COMDLG32.OCX be available and
correctly registered. (Note this is the control and NOT the Dll, which all Windows systems have)
If the Common Dialog class is included as a class module in a Visual Basic project, no other files are
required. If the class is compiled as an in-process server, the resulting DLL will need to be available at run
time and must be correctly registered.

The Win32 Common Dialog object is easier to use than the Visual Basic Common Dialog control because
it doesn't need to be a part of a form, so there is less over head ie you don't need to have the users
ensure that they have this control. The Common Dialog object (DLL) provides the same methods and
properties as the Common Dialog control (OCX) and it can be used to replace the Common Dialog
control in existing projects with very little modification to code.

Here is a list of the API functions available in the Dll. Note the double Entry points for ANSI or UNICODE
are designated by the last letter A (ANSI) or W(Wide character = UNICODE)
These functions were extracted via the "UsesWhat" utility available HERE
This utility scans import tables of Win32 executables for references to libraries and/or APIs.

  • ChooseColorA
  • ChooseColorW
  • ChooseFontA
  • ChooseFontW
  • CommDlgExtendedError
  • FindTextA
  • FindTextW
  • GetFileTitleA
  • GetFileTitleW
  • GetOpenFileNameA
  • GetOpenFileNameW
  • GetSaveFileNameA
  • GetSaveFileNameW
  • PageSetupDlgA
  • PageSetupDlgW
  • PrintDlgA
  • PrintDlgExW
  • PrintDlgW
  • ReplaceTextA
  • ReplaceTextW
  • Ssync_ANSI_UNICODE_Struct_For_WOW

For VBA users you will note from above the GetOpenFileName & GetSaveFileName,
do these look familiar ?

Yes it is basically the same. Here is the help file info;

Syntax

expression.GetOpenFilename(FileFilter, FilterIndex, Title, ButtonText, MultiSelect)

expression   Required. An expression that returns an Application object.

FileFilter   Optional Variant. A string specifying file filtering criteria.

This string consists of pairs of file filter strings followed by the MS-DOS wildcard file filter specification,
with each part and each pair separated by commas. Each separate pair is listed in the Files of type
drop-down list box.
For example, the following string specifies two file filters—text and addin:
"Text Files (*.txt),*.txt,Add-In Files (*.xla),*.xla".

To use multiple MS-DOS wildcard expressions for a single file filter type, separate the wildcard expressions with semicolons; for example, "Visual Basic Files (*.bas; *.txt),*.bas;*.txt".

If omitted, this argument defaults to "All Files (*.*),*.*".

FilterIndex   Optional Variant. Specifies the index numbers of the default file filtering criteria, from 1 to the
                                           number of filters specified in FileFilter. If this argument is omitted or greater
                                           than the number of filters present, the first file filter is used.

Title            Optional Variant. Specifies the title of the dialog box. If this argument is omitted,
                                           the title is "Open."

ButtonText   Optional Variant. Macintosh only.

MultiSelect   Optional Variant. True to allow multiple file names to be selected.
                                            False to allow only one file name to be selected. The default value is False

Remarks

This method returns the selected file name or the name entered by the user. The returned name may
include a path specification. If MultiSelect is True, the return value is an array of the selected file names
(even if only one filename is selected). Returns False if the user cancels the dialog box.

This method may change the current drive or folder.

Now that we have this out of the way lets look @ why I brought this up.

Using VBA GetOpenFileName, you may wish to filter for certain files eg *.txt = ALL Txt Files, but what
about All Txt files starting with B. You would naturally assume that you can do this via wild card subst
eg B*.txt, or what about ALL Txt files with the letters BE in the file name ??.
Then we would put in *BE*.Txt. Try this and see what happens ?

That's right, it won't work, you are limited with VBA FileOpen function filtering.

FILTERING FILES

Here is a work around for this - using the comdlg32.dll and the API function GetOpenFileNameA.

Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
   Alias "GetOpenFileNameA" ( _
   pOpenfilename As OPENFILENAME) As Long

Getting started

Before we use this API function we need to define a Type structure for the pOpenfilename.
As this function is similar to the OCX control, then it's properties should be the same, and they are
except for a few minor details. Here are the properties;
My thanks to Mark O'Brien for alerting me to the frustrating fact that the code pages do NOT copy, if at all

[COPY FRIENDLY PAGE]
So now all you have to do is define your filtering to get a list in a specified directory.

eg All .xls files with the letters "Help" in it would be defined as;

strFilter = "My XlFiles (*Help*.xls)" & Chr(0) & "*Help*.xls" & Chr(0)

NOTE: The filtered list needs to be padded with the null character Chr(0) to indicate and end of string.
This page was last updated on; June 10, 2003
How do you print your files? If you're using cheap Xerox Phaser ink, then you're smartly saving money! If you don't order Okidata toner cartridges online, you're not getting the best deal you could be getting. Find Dell toner cartridges online and start saving.