ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   InputBox - Browse (https://www.excelbanter.com/excel-programming/301969-inputbox-browse.html)

banavas[_7_]

InputBox - Browse
 
Dear Friends,

how can I add a browse button on an inputbox? I added a default value
(path) but I want to give the user the option to select a file to read
through a browse button.

Thanks,
G.


---
Message posted from http://www.ExcelForum.com/


Bob Phillips[_6_]

InputBox - Browse
 
This code below will run a folder browse dialog and return the selected
folder

This is a demo of how to use it

MsgBox GetFolder

Watch wrap-around.


'==============================
'Code starts here

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

'-------------------------------------------------------------
Function GetFolder(Optional ByVal Name As String = "Select a folder.")
As String
'-------------------------------------------------------------
Dim bInfo As BROWSEINFO
Dim path As String
Dim oDialog As Long

bInfo.pidlRoot = 0& 'Root folder = Desktop

bInfo.lpszTitle = Name

bInfo.ulFlags = &H1 'Type of directory to return
oDialog = SHBrowseForFolder(bInfo) 'display the dialog

'Parse the result
path = Space$(512)

GetFolder = ""
If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
End If

End Function



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"banavas " wrote in message
...
Dear Friends,

how can I add a browse button on an inputbox? I added a default value
(path) but I want to give the user the option to select a file to read
through a browse button.

Thanks,
G.


---
Message posted from http://www.ExcelForum.com/




Rob van Gelder[_4_]

InputBox - Browse
 
Works OK for the most part, but you can select cells while the dialog is
open.

You can get around it by doing something like:

Private Declare Function FindWindow Lib "user32.dll" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

....

bInfo.hOwner = FindWindow(vbNullString, Application.Caption)


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Bob Phillips" wrote in message
...
This code below will run a folder browse dialog and return the selected
folder

This is a demo of how to use it

MsgBox GetFolder

Watch wrap-around.


'==============================
'Code starts here

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

'-------------------------------------------------------------
Function GetFolder(Optional ByVal Name As String = "Select a folder.")
As String
'-------------------------------------------------------------
Dim bInfo As BROWSEINFO
Dim path As String
Dim oDialog As Long

bInfo.pidlRoot = 0& 'Root folder = Desktop

bInfo.lpszTitle = Name

bInfo.ulFlags = &H1 'Type of directory to return
oDialog = SHBrowseForFolder(bInfo) 'display the dialog

'Parse the result
path = Space$(512)

GetFolder = ""
If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
End If

End Function



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"banavas " wrote in message
...
Dear Friends,

how can I add a browse button on an inputbox? I added a default value
(path) but I want to give the user the option to select a file to read
through a browse button.

Thanks,
G.


---
Message posted from http://www.ExcelForum.com/






Stephen Bullen[_3_]

InputBox - Browse
 
Hi Banavas,

how can I add a browse button on an inputbox? I added a default value
(path) but I want to give the user the option to select a file to read
through a browse button.


Create your own userform for the input box and instead of a normal text
box, use a ComboBox with the dropdown style set to ellipsis. Then in
the _Dropdown event procedure, add the code to show the Browse dialog.

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.ie



Tom Ogilvy

InputBox - Browse
 
If you want to select a file, it might be just as straight forward to put a
command button on a userform and have the command button issue a

Chdrive "C"
Chdir "C:\My Default Folder"
fName = Application.GetOpenFileName

see help on GetOpenFileName for argument options.

There isn't much you can do with an inputbox itself using built in
capabilities.

--
Regards,
Tom Ogilvy

"banavas " wrote in message
...
Dear Friends,

how can I add a browse button on an inputbox? I added a default value
(path) but I want to give the user the option to select a file to read
through a browse button.

Thanks,
G.


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 01:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com