Thanks Matt
I ve added the ability to create a couple of sub folders as well as that was something I needed and may be useful and have done a KB Entry for the code as below
Private Const BIF_RETURNONLYFSDIRS As Long = &H1
Private Const BIF_DONTGOBELOWDOMAIN As Long = &H2
Private Const BIF_RETURNFSANCESTORS As Long = &H8
Private Const BIF_BROWSEFORCOMPUTER As Long = &H1000
Private Const BIF_BROWSEFORPRINTER As Long = &H2000
Private Const BIF_BROWSEINCLUDEFILES As Long = &H4000
Private Const MAX_PATH As Long = 260
'if you want the ability to create a new directory in the same pop-up window
'(and you have windows 2000 or greater), then add the following line
'Private Const BIF_NEWDIALOGSTYLE As Long = &H64
Type BrowseInfo
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszINSTRUCTIONS As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Boolean
hNameMappings As Long
lpszProgressTitle As String
End Type
Declare Function SHGetPathFromIDListA Lib "shell32.dll" ( _
ByVal pidl As Long, _
ByVal pszBuffer As String) As Long
Declare Function SHBrowseForFolderA Lib "shell32.dll" ( _
lpBrowseInfo As BrowseInfo) As Long
Function BrowseFolder(Optional Caption As String = "") As String
Dim BrowseInfo As BrowseInfo
Dim FolderName As String
Dim ID As Long
Dim Res As Long
With BrowseInfo
.hOwner = 0
.pidlRoot = 0
.pszDisplayName = String$(MAX_PATH, vbNullChar)
.lpszINSTRUCTIONS = Caption
.ulFlags = BIF_RETURNONLYFSDIRS
'If win 2000 or above
'.ulFlags = BIF_RETURNONLYFSDIR Or BIF_NEWDIALOGSTYLE
.lpfn = 0
End With
FolderName = String$(MAX_PATH, vbNullChar)
ID = SHBrowseForFolderA(BrowseInfo)
If ID Then
Res = SHGetPathFromIDListA(ID, FolderName)
If Res Then
BrowseFolder = Left$(FolderName, InStr(FolderName, _
vbNullChar) - 1)
End If
End If
End Function
Sub Test()
Dim FName As String
Dim WbName As String
Dim Search As String
Dim Prompt As String
Dim Title As String
On Error GoTo Err:
FName = BrowseFolder("Select A Folder")
If FName = "" Then
MsgBox "You didn't select a folder"
Else
Prompt = "Please Select a name for your enquiry?"
Title = "Enquiry Name"
Search = InputBox(Prompt, Title)
If Search = "" Then Exit Sub
End If
FName = FName & "\" & Search
MkDir FName
MsgBox FName & " created"
End If
Sheets("Hidden").Range("B1").Value = Search
ActiveWorkbook.SaveAs FName & "\" & Search & ".xls"
MkDir ActiveWorkbook.Path & "\TestDir1"
MkDir ActiveWorkbook.Path & "\TestDir2"
End
Err:
MsgBox " There has been an error, Please ensure the directory does not already exist"
End Sub