VBA EXCEL To Prompt User Response to Select Folder and Return the Path as String Variable [duplicate]
up vote
3
down vote
favorite
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.
excel vba excel-vba
marked as duplicate by Portland Runner, Siddharth Rout
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.
add a comment |
up vote
3
down vote
favorite
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.
excel vba excel-vba
marked as duplicate by Portland Runner, Siddharth Rout
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 addMsgbox Ret
afterRet = BrowseForFolder("C:")
then you will get the folder path as string provided the user didn't pressCancel
– Siddharth Rout
Oct 15 '14 at 22:57
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
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.
excel vba excel-vba
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
excel vba excel-vba
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
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
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 addMsgbox Ret
afterRet = BrowseForFolder("C:")
then you will get the folder path as string provided the user didn't pressCancel
– Siddharth Rout
Oct 15 '14 at 22:57
add a comment |
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 addMsgbox Ret
afterRet = BrowseForFolder("C:")
then you will get the folder path as string provided the user didn't pressCancel
– 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
add a comment |
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
1
Nice one GS!!!!
– ryguy72
Apr 19 '17 at 16:02
add a comment |
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
1
Nice one GS!!!!
– ryguy72
Apr 19 '17 at 16:02
add a comment |
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
1
Nice one GS!!!!
– ryguy72
Apr 19 '17 at 16:02
add a comment |
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
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
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
add a comment |
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
add a comment |
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
afterRet = BrowseForFolder("C:")
then you will get the folder path as string provided the user didn't pressCancel
– Siddharth Rout
Oct 15 '14 at 22:57