From: Oswald on
Hello

I'm trying to understand Stephen Bullen's and Rob Bovey's
GetOpenFileName routine which appears
to do something the standard GetOpenFileName doesn't. I'm noticing
that the filename under the cursor
is immediately reflected in the Filename combo box whenever the valid
selection is changed. Is this an
indication that the change of filename could trigger additional code
while the dialog is still active?
For example to populate a small worksheet range with text from a
".txt" file to illuminate it's content.

Thanks in advance
Oswald

BTW This group is excellent!
From: joel on

You may want to understand dialog boxes better. All dialog boxes are
par tof the comdlg32.dll (common dialog) in the windows\system32 folder.
Excel dates back to Office 97 and the standard VBA Getopenfilenames
only impliments the feature available at the time Office 97 was released
so Excel stys upward compatible from version to version.

GetOpenfile name in VBA is only a wrapper which calls the comdlg32.dll.
Yo can get the complete definition of the Current GetOPenfilename from
the DLL library definition at

'GetOpenFileName Function ()'
(http://msdn.microsoft.com/en-us/library/ms646927(VS.85).aspx)

From VBA you can call any DLL by simply defining the library call.

Below is some code I wrote which uses the Folder Picker using the same
DLL. I was working with somebody who was using Excel 2000 which didn't
have this dialog built into VBA. Actually the File Picker Dialog
(GETOPENFILENAME) and the folder Picker Dialog are vfery similar and
just called the same low level routines with different options.




Private Const BIF_RETURNONLYFSDIRS As Long = &H1
Private Const BIF_DONTGOBELOWDOMAIN As Long = &H2
Private Const BIF_RETURNFSANCESTORS As Long = &H8
Private Const BIF_BROWSEFORCOMPUTER As Long = &H1000
Private Const BIF_BROWSEFORPRINTER As Long = &H2000
Private Const BIF_BROWSEINCLUDEFILES As Long = &H4000
Private Const MAX_PATH As Long = 260

Type BrowseInfo
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszINSTRUCTIONS As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Boolean
hNameMappings As Long
lpszProgressTitle As String
End Type

Declare Function SHGetPathFromIDListA Lib "shell32.dll" ( _
ByVal pidl As Long, _
ByVal pszBuffer As String) As Long

Declare Function SHBrowseForFolderA Lib "shell32.dll" ( _
lpBrowseInfo As BrowseInfo) As Long


Function BrowseFolder(Optional Caption As String = "") As String

Dim BrowseInfo As BrowseInfo
Dim FolderName As String
Dim ID As Long
Dim Res As Long

With BrowseInfo
.hOwner = 0
.pidlRoot = 0
.pszDisplayName = String$(MAX_PATH, vbNullChar)
.lpszINSTRUCTIONS = Caption
.ulFlags = BIF_RETURNONLYFSDIRS
.lpfn = 0
End With

FolderName = String$(MAX_PATH, vbNullChar)
ID = SHBrowseForFolderA(BrowseInfo)
If ID Then
Res = SHGetPathFromIDListA(ID, FolderName)
If Res Then
BrowseFolder = Left$(FolderName, InStr(FolderName, vbNullChar) -
1)
End If
End If

End Function


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=187210

http://www.thecodecage.com/forumz/chat.php

 | 
Pages: 1
Prev: Excel button problem
Next: link in macro