Results 1 to 6 of 6

Thread: Selecting a Path in Excel 2000

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    13

    Selecting a Path in Excel 2000

    I'm using Excel 2000 and I would like to bring up a dialog box that allows the user to select a Path. Does anyone have a solution for this? I've looked at a few API calls but none of them do specifically what I'd like...

    Any ideas on how to accomplish this? Up until now I've been using either a textbox to type in the path or a file open dialog box and asking the user to open a file in the directory that wish to select.

    Thanks,

    Dave

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Selecting a Path in Excel 2000

    Have you considered using the built-in "File Open" dialog box?
    You can call this by using the dialogs collection of the excel application.
    There are many arguments that you can use with the show method of the collection, including read-only, file type (.xls , .txt , etc.)....

    VB Code:
    1. Application.Dialogs(xlDialogOpen).Show
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Selecting a Path in Excel 2000

    What you want is a BrowseForFolder dialog. You can create one out of all APIs very easy from this example here.

    This will keep the user from getting confused with the OpenSave dialogs as they are prompting for a file to open or save.

    VB Code:
    1. 'Modified example:
    2.  
    3. Private Type BrowseInfo
    4.     hWndOwner As Long
    5.     pIDLRoot As Long
    6.     pszDisplayName As Long
    7.     lpszTitle As Long
    8.     ulFlags As Long
    9.     lpfnCallback As Long
    10.     lParam As Long
    11.     iImage As Long
    12. End Type
    13. Const BIF_RETURNONLYFSDIRS = 1
    14. Const MAX_PATH = 260
    15. Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
    16. Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    17. Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    18. Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
    19. Private Sub Command1_Click()
    20.     'KPD-Team 1998
    21.     'URL: [url]http://www.allapi.net/[/url]
    22.     Dim iNull As Integer, lpIDList As Long, lResult As Long
    23.     Dim sPath As String, udtBI As BrowseInfo
    24.  
    25.     With udtBI
    26.         'Set the owner window
    27.         .hWndOwner = Me.hWnd
    28.         'lstrcat appends the two strings and returns the memory address
    29.         .lpszTitle = lstrcat("C:\", "")
    30.         'Return only if the user selected a directory
    31.         .ulFlags = BIF_RETURNONLYFSDIRS
    32.     End With
    33.  
    34.     'Show the 'Browse for folder' dialog
    35.     lpIDList = SHBrowseForFolder(udtBI)
    36.     If lpIDList Then
    37.         sPath = String$(MAX_PATH, 0)
    38.         'Get the path from the IDList
    39.         SHGetPathFromIDList lpIDList, sPath
    40.         'free the block of memory
    41.         CoTaskMemFree lpIDList
    42.         iNull = InStr(sPath, vbNullChar)
    43.         If iNull Then
    44.             sPath = Left$(sPath, iNull - 1)
    45.         End If
    46.     End If
    47.  
    48.     MsgBox sPath
    49. End Sub
    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    13

    Re: Selecting a Path in Excel 2000

    Thanks, I haven't had a chance to try that yet but it sounds like what I am looking for! I'll have to figure out how to make API calls on my own some day. Any suggested reading (preferably free/sites but books are always an option) ?

    I've been working on moving from C to C++ and am hopinig to work APIs and MFC into that as well, perhaps it'd be better to wait until I cross that line?

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Selecting a Path in Excel 2000

    Check out allapi.net for allot of API tutorials and definitions.
    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

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Selecting a Path in Excel 2000

    You can find a list of most of them at www.allapi.net and also at MSDN On-Line.

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