Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'// Minimum DLL version shell32.dll version 4.71 or later
'// Minimum operating systems Windows 2000, Windows NT 4.0 with Internet Explorer 4.0,
'// Windows 98, Windows 95 with Internet Explorer 4.0
'// objFolder = objShell.BrowseForFolder(Hwnd, sTitle, BIF_Options [, vRootFolder])
Public Function BrowseForFolderShell( _
Optional Hwnd As Long = 0, _
Optional sTitle As String = "Browse for Folder", _
Optional BIF_Options As Integer = BIF_VALIDATE, _
Optional vRootFolder As Variant) As String
Dim objShell As Object
Dim objFolder As Variant
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 TesterI()
'// STD test
Dim strFolder As String
strFolder = BrowseForFolderShell(, , , 0)
If strFolder = vbNullString Then
MsgBox "You cancelled"
Else
MsgBox strFolder
End If
End Sub
[blue]Optional BIF_Options As Integer, _[/blue]
Dim UserFile As String
Dim whatnow As String
'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
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
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
GetDirectory = ""
End If
End Function
Sub GetDir()
Dim Msg As String
whatnow = "continue"
On Error Resume Next
Msg = "Select Directory to Store Output File in."
UserFile = GetDirectory(Msg) & "\"
If UserFile = "" Then
whatnow = "finish"
MsgBox "Canceled"
ElseIf Not ContinueProcedure Then
whatnow = "finish"
Exit Sub
End If
End Sub
Private Function ContinueProcedure() As Boolean
Dim Config As Integer
Dim Ans As Integer
Config = vbYesNo + vbQuestion + vbDefaultButton2
Ans = MsgBox(UserFile & " <<< Is This The Correct Directory?", Config)
If Ans = vbYes Then
ContinueProcedure = True
Else: ContinueProcedure = False
End If
End Function
'Routines above generate Folder Browse
'====================================================================================
'Routines below need to call GetDir to generate Browse window.
Sub YourMacro()
'your code
'------------------------------------------
Filename = InputBox("Enter the Task filename. You do not need to add the .TSK extension. It will be added automatically", "Task File - filename.TSK")
'Get the Directory Filepath for the output file
Call GetDir
Filename = UserFile & Filename + ".TSK"
ActiveWorkbook.SaveAs Filename:=Filename, FileFormat:=xlCSV, _
CreateBackup:=False
'------------------------------------------
'your code
End Sub