Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default 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/





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default 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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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/



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
Trying to browse Add-ins???? [email protected] Excel Discussion (Misc queries) 1 March 5th 08 08:47 PM
Browse Desktop jason2444 Excel Discussion (Misc queries) 0 August 6th 07 09:22 PM
Browse File for Mac John Vickers Excel Discussion (Misc queries) 1 February 17th 06 06:23 PM
can't browse file k_anucha Excel Discussion (Misc queries) 1 September 29th 05 01:51 AM
Browse Dialog Box in VBA? Raul[_4_] Excel Programming 5 May 12th 04 03:29 PM


All times are GMT +1. The time now is 01:57 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"