VBA EXCEL To Prompt User Response to Select Folder and Return the Path as String Variable [duplicate]











up vote
3
down vote

favorite
1













This question already has an answer here:




  • VBA - Folder Picker - set where to start [duplicate]

    5 answers



  • VBA Excel Getting File Path (ends with folder)

    6 answers




I am trying to write a VBA code where a dialog box would appear for the user to select where they want to save the files.
However, I just need the path value (e.g. c:DesktopValues) returned as a string variable so that I could use it in another function.
Any help would be appreciated.










share|improve this question















marked as duplicate by Portland Runner, Siddharth Rout excel
Users with the  excel badge can single-handedly close excel questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Oct 15 '14 at 22:55


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 2




    stackoverflow.com/questions/19372319/…
    – Alter
    Oct 15 '14 at 21:37










  • I want the full path name. Doesn't that just return Folder name?
    – David G
    Oct 15 '14 at 21:47










  • no, you can get the full path (see Gary's answer)
    – Alter
    Oct 15 '14 at 22:09






  • 1




    In the answer that I posted in the link given above, if you add Msgbox Ret after Ret = BrowseForFolder("C:") then you will get the folder path as string provided the user didn't press Cancel
    – Siddharth Rout
    Oct 15 '14 at 22:57















up vote
3
down vote

favorite
1













This question already has an answer here:




  • VBA - Folder Picker - set where to start [duplicate]

    5 answers



  • VBA Excel Getting File Path (ends with folder)

    6 answers




I am trying to write a VBA code where a dialog box would appear for the user to select where they want to save the files.
However, I just need the path value (e.g. c:DesktopValues) returned as a string variable so that I could use it in another function.
Any help would be appreciated.










share|improve this question















marked as duplicate by Portland Runner, Siddharth Rout excel
Users with the  excel badge can single-handedly close excel questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Oct 15 '14 at 22:55


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 2




    stackoverflow.com/questions/19372319/…
    – Alter
    Oct 15 '14 at 21:37










  • I want the full path name. Doesn't that just return Folder name?
    – David G
    Oct 15 '14 at 21:47










  • no, you can get the full path (see Gary's answer)
    – Alter
    Oct 15 '14 at 22:09






  • 1




    In the answer that I posted in the link given above, if you add Msgbox Ret after Ret = BrowseForFolder("C:") then you will get the folder path as string provided the user didn't press Cancel
    – Siddharth Rout
    Oct 15 '14 at 22:57













up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1






This question already has an answer here:




  • VBA - Folder Picker - set where to start [duplicate]

    5 answers



  • VBA Excel Getting File Path (ends with folder)

    6 answers




I am trying to write a VBA code where a dialog box would appear for the user to select where they want to save the files.
However, I just need the path value (e.g. c:DesktopValues) returned as a string variable so that I could use it in another function.
Any help would be appreciated.










share|improve this question
















This question already has an answer here:




  • VBA - Folder Picker - set where to start [duplicate]

    5 answers



  • VBA Excel Getting File Path (ends with folder)

    6 answers




I am trying to write a VBA code where a dialog box would appear for the user to select where they want to save the files.
However, I just need the path value (e.g. c:DesktopValues) returned as a string variable so that I could use it in another function.
Any help would be appreciated.





This question already has an answer here:




  • VBA - Folder Picker - set where to start [duplicate]

    5 answers



  • VBA Excel Getting File Path (ends with folder)

    6 answers








excel vba excel-vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 1 '15 at 21:30









Joe Shaw

13.5k145682




13.5k145682










asked Oct 15 '14 at 21:32









David G

29113




29113




marked as duplicate by Portland Runner, Siddharth Rout excel
Users with the  excel badge can single-handedly close excel questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Oct 15 '14 at 22:55


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Portland Runner, Siddharth Rout excel
Users with the  excel badge can single-handedly close excel questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Oct 15 '14 at 22:55


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 2




    stackoverflow.com/questions/19372319/…
    – Alter
    Oct 15 '14 at 21:37










  • I want the full path name. Doesn't that just return Folder name?
    – David G
    Oct 15 '14 at 21:47










  • no, you can get the full path (see Gary's answer)
    – Alter
    Oct 15 '14 at 22:09






  • 1




    In the answer that I posted in the link given above, if you add Msgbox Ret after Ret = BrowseForFolder("C:") then you will get the folder path as string provided the user didn't press Cancel
    – Siddharth Rout
    Oct 15 '14 at 22:57














  • 2




    stackoverflow.com/questions/19372319/…
    – Alter
    Oct 15 '14 at 21:37










  • I want the full path name. Doesn't that just return Folder name?
    – David G
    Oct 15 '14 at 21:47










  • no, you can get the full path (see Gary's answer)
    – Alter
    Oct 15 '14 at 22:09






  • 1




    In the answer that I posted in the link given above, if you add Msgbox Ret after Ret = BrowseForFolder("C:") then you will get the folder path as string provided the user didn't press Cancel
    – Siddharth Rout
    Oct 15 '14 at 22:57








2




2




stackoverflow.com/questions/19372319/…
– Alter
Oct 15 '14 at 21:37




stackoverflow.com/questions/19372319/…
– Alter
Oct 15 '14 at 21:37












I want the full path name. Doesn't that just return Folder name?
– David G
Oct 15 '14 at 21:47




I want the full path name. Doesn't that just return Folder name?
– David G
Oct 15 '14 at 21:47












no, you can get the full path (see Gary's answer)
– Alter
Oct 15 '14 at 22:09




no, you can get the full path (see Gary's answer)
– Alter
Oct 15 '14 at 22:09




1




1




In the answer that I posted in the link given above, if you add Msgbox Ret after Ret = BrowseForFolder("C:") then you will get the folder path as string provided the user didn't press Cancel
– Siddharth Rout
Oct 15 '14 at 22:57




In the answer that I posted in the link given above, if you add Msgbox Ret after Ret = BrowseForFolder("C:") then you will get the folder path as string provided the user didn't press Cancel
– Siddharth Rout
Oct 15 '14 at 22:57












1 Answer
1






active

oldest

votes

















up vote
19
down vote



accepted










Consider:



Function GetFolder() As String
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = Application.DefaultFilePath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
GetFolder = sItem
Set fldr = Nothing
End Function


This code was adapted from Ozgrid






share|improve this answer



















  • 1




    Nice one GS!!!!
    – ryguy72
    Apr 19 '17 at 16:02


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
19
down vote



accepted










Consider:



Function GetFolder() As String
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = Application.DefaultFilePath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
GetFolder = sItem
Set fldr = Nothing
End Function


This code was adapted from Ozgrid






share|improve this answer



















  • 1




    Nice one GS!!!!
    – ryguy72
    Apr 19 '17 at 16:02















up vote
19
down vote



accepted










Consider:



Function GetFolder() As String
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = Application.DefaultFilePath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
GetFolder = sItem
Set fldr = Nothing
End Function


This code was adapted from Ozgrid






share|improve this answer



















  • 1




    Nice one GS!!!!
    – ryguy72
    Apr 19 '17 at 16:02













up vote
19
down vote



accepted







up vote
19
down vote



accepted






Consider:



Function GetFolder() As String
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = Application.DefaultFilePath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
GetFolder = sItem
Set fldr = Nothing
End Function


This code was adapted from Ozgrid






share|improve this answer














Consider:



Function GetFolder() As String
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = Application.DefaultFilePath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
GetFolder = sItem
Set fldr = Nothing
End Function


This code was adapted from Ozgrid







share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 25 at 20:50

























answered Oct 15 '14 at 21:48









Gary's Student

71.2k93460




71.2k93460








  • 1




    Nice one GS!!!!
    – ryguy72
    Apr 19 '17 at 16:02














  • 1




    Nice one GS!!!!
    – ryguy72
    Apr 19 '17 at 16:02








1




1




Nice one GS!!!!
– ryguy72
Apr 19 '17 at 16:02




Nice one GS!!!!
– ryguy72
Apr 19 '17 at 16:02



Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy