sassriverrat
Well-known Member
- Joined
- Oct 4, 2018
- Messages
- 655
Good Afternoon,
A friend shot me this piece of code in my efforts to simplify a workbook. The code successfully opens a dialog box that allows the user to choose a "save" location, but I need this piece of code to spit the entire address into cell A1 and I've tried tweaking a few times to no success. Anyone have any ideas?
A friend shot me this piece of code in my efforts to simplify a workbook. The code successfully opens a dialog box that allows the user to choose a "save" location, but I need this piece of code to spit the entire address into cell A1 and I've tried tweaking a few times to no success. Anyone have any ideas?
Code:
Public Function GetOutputDirectory() As String
Dim retval As String 'Return Value
Dim sMsg As String
Dim cBits As Integer
Dim xRoot As Integer
Dim oShell As Object
Set oShell = CreateObject("shell.application")
sMsg = "Select a Folder To Output The Attachments To"
cBits = 1
xRoot = 17
On Error Resume Next
Dim oBFF
Set oBFF = oShell.BrowseForFolder(0, sMsg, cBits, xRoot)
If Err Then
Err.Clear
GetOutputDirectory = ""
Exit Function
End If
On Error GoTo 0
If Not IsObject(oBFF) Then
GetOutputDirectory = ""
Exit Function
End If
If Not (LCase(Left(Trim(TypeName(oBFF)), 6)) = "folder") Then
retval = ""
Else
retval = oBFF.Self.Path
'Make sure there's a \ on the end
If Right(retval, 1) <> "\" Then
retval = retval + "\"
End If
End If
GetOutputDirectory = retval
End Function
Sub output_directory()
Dim outputDir As String
outputDir = GetOutputDirectory()
If outputDir = "" Then
MsgBox "You must pick an directory to save your files to. Exiting SaveAttachments.", vbCritical, "SaveAttachments"
Exit Sub
End If
End Sub[\code]