Results 1 to 3 of 3

Thread: browse

  1. #1

    Thread Starter
    Member
    Join Date
    May 2004
    Location
    Where i am
    Posts
    38

    browse

    How do you make browse buttons in Microsoft Excel because i am making something for someone who isn't good with typing file addresses?

  2. #2
    New Member
    Join Date
    Oct 2004
    Posts
    4
    Hi ,

    U jus type in the required data in any unused part of your worksheet and goto the cell where u want the data

    use alt+DL (DATA->Validation)one the first box drop down any select list
    on the second one select the red botton use arrow bottons to move to the place where u have entered the data eariler
    press shift and select the list
    hit enter and u have the validation done.

    Hope this makes sense???

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Do you mean a CommonDialog browse box?Like when you do a
    Save As... etc.

    Place in a standard module:


    VB Code:
    1. Option Explicit
    2.  
    3. Public Const LF_FACESIZE = 32
    4. Public Const MAX_PATH = 260
    5.  
    6. 'ShowOpen/ShowSave flags:
    7. Public Const OFN_ALLOWMULTISELECT = &H200
    8. Public Const OFN_CREATEPROMPT = &H2000
    9. Public Const OFN_ENABLEHOOK = &H20
    10. Public Const OFN_ENABLETEMPLATE = &H40
    11. Public Const OFN_ENABLETEMPLATEHANDLE = &H80
    12. Public Const OFN_EXPLORER = &H80000
    13. Public Const OFN_EXTENSIONDIFFERENT = &H400
    14. Public Const OFN_FILEMUSTEXIST = &H1000
    15. Public Const OFN_HIDEREADONLY = &H4
    16. Public Const OFN_LONGNAMES = &H200000
    17. Public Const OFN_NOCHANGEDIR = &H8
    18. Public Const OFN_NODEREFERENCELINKS = &H100000
    19. Public Const OFN_NOLONGNAMES = &H40000
    20. Public Const OFN_NONETWORKBUTTON = &H20000
    21. Public Const OFN_NOREADONLYRETURN = &H8000
    22. Public Const OFN_NOTESTFILECREATE = &H10000
    23. Public Const OFN_NOVALIDATE = &H100
    24. Public Const OFN_OVERWRITEPROMPT = &H2
    25. Public Const OFN_PATHMUSTEXIST = &H800
    26. Public Const OFN_READONLY = &H1
    27. Public Const OFN_SHAREAWARE = &H4000
    28. Public Const OFN_SHAREFALLTHROUGH = 2
    29. Public Const OFN_SHARENOWARN = 1
    30. Public Const OFN_SHAREWARN = 0
    31. Public Const OFN_SHOWHELP = &H10
    32. Public Const OFS_MAXPATHNAME = 128
    33.  
    34. 'BrowseForFolder flags:
    35. Public Const BIF_RETURNONLYFSDIRS = &H1       ' For finding a folder to start document searching
    36. Public Const BIF_DONTGOBELOWDOMAIN = &H2      ' For starting the Find Computer
    37. Public Const BIF_STATUSTEXT = &H4
    38. Public Const BIF_RETURNFSANCESTORS = &H8
    39. Public Const BIF_BROWSEFORCOMPUTER = &H1000   ' Browsing for Computers.
    40. Public Const BIF_BROWSEFORPRINTER = &H2000    ' Browsing for Printers
    41. Public Const BIF_BROWSEINCLUDEFILES = &H4000  ' Browsing for Everything
    42.  
    43. 'Error constants
    44. Public Const CDERR_DIALOGFAILURE = &HFFFF
    45. Public Const CDERR_FINDRESFAILURE = &H6
    46. Public Const CDERR_GENERALCODES = &H0
    47. Public Const CDERR_INITIALIZATION = &H2
    48. Public Const CDERR_LOADRESFAILURE = &H7
    49. Public Const CDERR_LOADSTRFAILURE = &H5
    50. Public Const CDERR_LOCKRESFAILURE = &H8
    51. Public Const CDERR_MEMALLOCFAILURE = &H9
    52. Public Const CDERR_MEMLOCKFAILURE = &HA
    53. Public Const CDERR_NOHINSTANCE = &H4
    54. Public Const CDERR_NOHOOK = &HB
    55. Public Const CDERR_REGISTERMSGFAIL = &HC
    56. Public Const CDERR_NOTEMPLATE = &H3
    57. Public Const CDERR_STRUCTSIZE = &H1
    58.  
    59. 'Types
    60. Type POINTAPI
    61.     x As Long
    62.     y As Long
    63. End Type
    64.  
    65. Type RECT
    66.     Left As Long
    67.     Top As Long
    68.     Right As Long
    69.     Bottom As Long
    70. End Type
    71.  
    72. Type OPENFILENAME
    73.     lStructSize As Long
    74.     hwndOwner As Long
    75.     hInstance As Long
    76.     lpstrFilter As String
    77.     lpstrCustomFilter As String
    78.     nMaxCustFilter As Long
    79.     nFilterIndex As Long
    80.     lpstrFile As String
    81.     nMaxFile As Long
    82.     lpstrFileTitle As String
    83.     nMaxFileTitle As Long
    84.     lpstrInitialDir As String
    85.     lpstrTitle As String
    86.     flags As Long
    87.     nFileOffset As Integer
    88.     nFileExtension As Integer
    89.     lpstrDefExt As String
    90.     lCustData As Long
    91.     lpfnHook As Long
    92.     lpTemplateName As String
    93. End Type
    94.  
    95. Type BROWSEINFO
    96.     hwndOwner As Long
    97.     pIDLRoot As Long
    98.     pszDisplayName As Long
    99.     lpszTitle As Long
    100.     ulFlags As Long
    101.     lpfnCallback As Long
    102.     lParam As Long
    103.     iImage As Long
    104. End Type
    105.  
    106. Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
    107.  
    108. Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal _
    109. lpString1 As String, ByVal lpString2 As String) As Long
    110.  
    111. Declare Function SHBrowseForFolder Lib "shell32" (lpbi As _
    112. BROWSEINFO) As Long
    113.  
    114. Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList _
    115. As Long, ByVal lpBuffer As String) As Long
    116.  
    117. Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
    118. (pOpenfilename As OPENFILENAME) As Long
    119.  
    120. Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" _
    121. (pOpenfilename As OPENFILENAME) As Long
    122.  
    123. Declare Function GetFileTitleAPI Lib "comdlg32.dll" Alias "GetFileTitleA" _
    124. (ByVal lpszFile As String, ByVal lpszTitle As String, ByVal cbBuf As Integer) As Integer
    125.  
    126. Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
    127.  
    128. Global OFName As OPENFILENAME
    129. Global BInfo As BROWSEINFO
    130.  
    131. Public Function ShowOpen(hwndOwner As Long, sFilter As String, sTitle As String, Optional nFlags As Long = OFN_EXPLORER) As String
    132.    
    133.     OFName.lStructSize = Len(OFName)
    134.     OFName.hwndOwner = hwndOwner
    135.     OFName.hInstance = App.hInstance
    136.     OFName.lpstrFilter = sFilter
    137.     OFName.lpstrFile = String(254, vbNullChar)
    138.     OFName.nMaxFile = 255
    139.     OFName.lpstrFileTitle = String(254, vbNullChar)
    140.     OFName.nMaxFileTitle = 255
    141.     OFName.lpstrTitle = sTitle
    142.     OFName.flags = nFlags
    143.  
    144.     If GetOpenFileName(OFName) Then
    145.         ShowOpen = StripTerminator(OFName.lpstrFile)
    146.     Else
    147.         ShowOpen = ""
    148.     End If
    149.    
    150. End Function
    151.  
    152. Public Function ShowSave(hwndOwner As Long, sFilter As String, sTitle As String, Optional nFlags As Long = OFN_EXPLORER) As String
    153.    
    154.     OFName.lStructSize = Len(OFName)
    155.     OFName.hwndOwner = hwndOwner
    156.     OFName.hInstance = App.hInstance
    157.     OFName.lpstrFilter = sFilter
    158.     OFName.lpstrFile = String(254, vbNullChar)
    159.     OFName.nMaxFile = 255
    160.     OFName.lpstrFileTitle = String(254, vbNullChar)
    161.     OFName.nMaxFileTitle = 255
    162.     OFName.lpstrTitle = sTitle
    163.     OFName.flags = nFlags
    164.  
    165.     If GetSaveFileName(OFName) Then
    166.         ShowSave = StripTerminator(OFName.lpstrFile)
    167.     Else
    168.         ShowSave = ""
    169.     End If
    170.    
    171. End Function
    172.  
    173. Public Function BrowseForFolder(hwndOwner As Long, sTitle As String) As String
    174.  
    175.     Dim iNull As Integer
    176.     Dim lpIDList As Long
    177.     Dim lResult As Long
    178.  
    179.     With BInfo
    180.         .hwndOwner = hwndOwner
    181.         .lpszTitle = lstrcat(sTitle, "")
    182.         .ulFlags = BIF_RETURNONLYFSDIRS
    183.     End With
    184.  
    185.     lpIDList = SHBrowseForFolder(BInfo)
    186.     If lpIDList Then
    187.         BrowseForFolder = String$(MAX_PATH, 0)
    188.         SHGetPathFromIDList lpIDList, BrowseForFolder
    189.         CoTaskMemFree lpIDList
    190.         BrowseForFolder = StripTerminator(BrowseForFolder)
    191.     End If
    192.    
    193. End Function
    194.  
    195. Public Function GetFileTitle(sFile As String) As String
    196.  
    197.     GetFileTitle = String(255, vbNullChar)
    198.     GetFileTitleAPI sFile, GetFileTitle, 255
    199.     GetFileTitle = StripTerminator(GetFileTitle)
    200.    
    201. End Function
    202.  
    203. Public Function GetErrorString() As String
    204.  
    205.     Select Case CommDlgExtendedError
    206.         Case CDERR_DIALOGFAILURE
    207.             GetErrorString = "The dialog box could not be created."
    208.         Case CDERR_FINDRESFAILURE
    209.             GetErrorString = "The common dialog box function failed to find a specified resource."
    210.         Case CDERR_INITIALIZATION
    211.             GetErrorString = "The common dialog box function failed during initialization."
    212.         Case CDERR_LOADRESFAILURE
    213.             GetErrorString = "The common dialog box function failed to load a specified resource."
    214.         Case CDERR_LOADSTRFAILURE
    215.             GetErrorString = "The common dialog box function failed to load a specified string."
    216.         Case CDERR_LOCKRESFAILURE
    217.             GetErrorString = "The common dialog box function failed to lock a specified resource."
    218.         Case CDERR_MEMALLOCFAILURE
    219.             GetErrorString = "The common dialog box function was unable to allocate memory for internal structures."
    220.         Case CDERR_MEMLOCKFAILURE
    221.             GetErrorString = "The common dialog box function was unable to lock the memory associated with a handle."
    222.         Case CDERR_NOHINSTANCE
    223.             GetErrorString = "The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box, but you failed to provide a corresponding instance handle."
    224.         Case CDERR_NOHOOK
    225.             GetErrorString = "The ENABLEHOOK flag was set in the Flags member of the initialization structure for the corresponding common dialog box, but you failed to provide a pointer to a corresponding hook procedure."
    226.         Case CDERR_REGISTERMSGFAIL
    227.             GetErrorString = "The RegisterWindowMessage function returned an error code when it was called by the common dialog box function."
    228.         Case CDERR_NOTEMPLATE
    229.             GetErrorString = "The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box, but you failed to provide a corresponding template."
    230.         Case CDERR_STRUCTSIZE
    231.             GetErrorString = "The lStructSize member of the initialization structure for the corresponding common dialog box is invalid."
    232.         Case Else
    233.             GetErrorString = "Undefined error ..."
    234.     End Select
    235.    
    236. End Function
    237.  
    238. Private Function StripTerminator(sInput As String) As String
    239.  
    240.     Dim ZeroPos As Integer
    241.    
    242.     ZeroPos = InStr(1, sInput, vbNullChar)
    243.     If ZeroPos > 0 Then
    244.         StripTerminator = Left$(sInput, ZeroPos - 1)
    245.     Else
    246.         StripTerminator = sInput
    247.     End If
    248.    
    249. End Function
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width