Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default set last used for getting directory

1) Using the following code, I would like the file browser open up to the
last used directory.

2) I borrowed this code from previous posts, but I do not clearly
understand it. Could anyone direct me to a source where I could study this
more in depth?

Thank You.

Smokii

Option Explicit

Public 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


'32-bit API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String)
As Long


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

Function GetDirectory(Optional msg) As String
Dim bInfo As BROWSEINFO
Dim path As String
Dim r As Long, x As Long, pos As Integer


' Root folder = Desktop
bInfo.pidlRoot = 0&


' Title in the dialog
If IsMissing(msg) Then
bInfo.lpszTitle = "Select a folder."
Else
bInfo.lpszTitle = msg
End If


' Type of directory to return
bInfo.ulFlags = &H1


' Display the dialog
x = SHBrowseForFolder(bInfo)


' Parse the result
path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, pos - 1)
Else
call Cancel
End If
End Function
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default set last used for getting directory

Hello,

Ssee the following at Ivan F Moala's site:

http://www.xcelfiles.com/Shell32_00.html

Change Sub TesterIII() to pass CurDir. I.e.,

'-------------------------------
Sub TesterIII()
'// Using String
'// This will not only limit the User to a specific Folder
Dim strFolder As String

strFolder = BrowseForFolderShell(, , , CurDir)

If strFolder = vbNullString Then
MsgBox "You cancelled"
Else
MsgBox strFolder
End If

End Sub
'-------------------------------

Regards,
Nate Oliver

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default set last used for getting directory

strFolder = BrowseForFolderShell(, , , CurDir)

this line yields an error: "Sub or Function not defined"

Did I miss something?

Smokii



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default set last used for getting directory

Did I miss something?

Yes, the function that Sub TesterIII() is calling, that being
BrowseForFolderShell().

Try the following:

'-------------------------------------------------------------------------
Public Function BrowseForFolderShell( _
Optional Hwnd As Long = 0, _
Optional sTitle As String = vbNullString, _
Optional BIF_Options As Long = &H20, _
Optional vRootFolder As Variant) As String

Dim objShell As Object
Dim objFolder As Object
Dim strFolderFullPath As String

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell. _
BrowseForFolder(Hwnd, sTitle, BIF_Options, vRootFolder)

If (Not objFolder Is Nothing) Then
'// NB: If SpecFolder= 0 = Desktop then ....
On Error Resume Next
If IsError(objFolder.Items.Item.Path) Then _
strFolderFullPath = CStr(objFolder): GoTo GotIt
On Error GoTo 0
'// Is it the Root Dir?...if so change
If Len(objFolder.Items.Item.Path) 3 Then
strFolderFullPath = objFolder.Items.Item.Path & _
Application.PathSeparator
Else
strFolderFullPath = objFolder.Items.Item.Path
End If
Else
'// User cancelled
GoTo XitProperly
End If

GotIt:
BrowseForFolderShell = strFolderFullPath

XitProperly:
Set objFolder = Nothing
Set objShell = Nothing

End Function

Sub TesterIII()
'// Using String
'// This will not only limit the User to a specific Folder
Dim strFolder As String

Call BrowseForFolderShell(, , , CurDir)

If strFolder = vbNullString Then
MsgBox "You cancelled"
Else
MsgBox strFolder
End If

End Sub
'-------------------------------------------------------------------------

Regards,
Nate Oliver
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default set last used for getting directory

Yikes, use the function I last posted, do not use the routing 'TesterIII()'.

Use:

Sub TesterIII()
'// Using String
'// This will not only limit the User to a specific Folder
Dim strFolder As String

Let strFolder = BrowseForFolderShell(, , , CurDir)

If strFolder = vbNullString Then
MsgBox "You cancelled"
Else
MsgBox strFolder
End If

End Sub
'----------------

You want to pass the string to a variable. Sorry about the confusion.

Regards,
Nate Oliver


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default set last used for getting directory

it works...but it does not allow me to climb back up the directory from
the last used folder.

Smokii

"?B?TmF0ZSBPbGl2ZXI=?="
wrote in :

Did I miss something?


Yes, the function that Sub TesterIII() is calling, that being
BrowseForFolderShell().

Try the following:

'----------------------------------------------------------------------
--- Public Function BrowseForFolderShell( _
Optional Hwnd As Long = 0, _
Optional sTitle As String = vbNullString, _
Optional BIF_Options As Long = &H20, _
Optional vRootFolder As Variant) As String

Dim objShell As Object
Dim objFolder As Object
Dim strFolderFullPath As String

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell. _
BrowseForFolder(Hwnd, sTitle, BIF_Options, vRootFolder)

If (Not objFolder Is Nothing) Then
'// NB: If SpecFolder= 0 = Desktop then ....
On Error Resume Next
If IsError(objFolder.Items.Item.Path) Then _
strFolderFullPath = CStr(objFolder): GoTo GotIt
On Error GoTo 0
'// Is it the Root Dir?...if so change
If Len(objFolder.Items.Item.Path) 3 Then
strFolderFullPath = objFolder.Items.Item.Path & _
Application.PathSeparator
Else
strFolderFullPath = objFolder.Items.Item.Path
End If
Else
'// User cancelled
GoTo XitProperly
End If

GotIt:
BrowseForFolderShell = strFolderFullPath

XitProperly:
Set objFolder = Nothing
Set objShell = Nothing

End Function

Sub TesterIII()
'// Using String
'// This will not only limit the User to a specific Folder
Dim strFolder As String

Call BrowseForFolderShell(, , , CurDir)

If strFolder = vbNullString Then
MsgBox "You cancelled"
Else
MsgBox strFolder
End If

End Sub
'----------------------------------------------------------------------
---

Regards,
Nate Oliver


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default How to postion folder browser

I am using the following code below to select a folder, but the dialog
always appears in the upper right of my screen. How do I position this
dialog closer to the center of the screen? or, in parallel with one of
my recent posts, how could I have the dialog appear where it was last
moved to?

I would also like the browser to open up to the last chosen directory.

'--------------------------------------------------------------
Option Explicit

Public 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


'32-bit API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As
String) As Long


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

Function GetDirectory(Optional msg) As String
Dim bInfo As BROWSEINFO
Dim path As String
Dim r As Long, x As Long, pos As Integer


' Root folder = Desktop
bInfo.pidlRoot = 0&


' Title in the dialog
If IsMissing(msg) Then
bInfo.lpszTitle = "Select a folder."
Else
bInfo.lpszTitle = msg
End If


' Type of directory to return
bInfo.ulFlags = &H1


' Display the dialog
x = SHBrowseForFolder(bInfo)


' Parse the result
path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, pos - 1)
Else
call Cancel
End If
End Function
'--------------------------------------------------------------


Thanks for your help.

Smokii
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default set last used for getting directory

No, it doesn't:

http://msdn.microsoft.com/library/en...eforfolder.asp

See the description of the vRootFolder parameter.

Regards,
Nathan Oliver

"smokiibear" wrote:

it works...but it does not allow me to climb back up the directory from
the last used folder.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default How to postion folder browser

opps... i ment for this to be a new post...but just just as well. Sorry

smokii

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
Directory Jeff Excel Discussion (Misc queries) 1 October 5th 06 04:51 PM
Change directory Jeff Excel Discussion (Misc queries) 6 September 27th 06 04:08 PM
Creating a macro that lists directory names within a directory.... Andy Excel Programming 4 November 28th 04 06:13 AM
Check if directory empty OR no of files in directory. Michael Beckinsale Excel Programming 2 December 4th 03 10:12 PM
Directory checking Eric[_6_] Excel Programming 0 July 11th 03 03:53 PM


All times are GMT +1. The time now is 07:54 PM.

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"