ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   File Path Problem (https://www.excelbanter.com/excel-programming/286052-file-path-problem.html)

Todd Huttenstine[_2_]

File Path Problem
 
Below is a code that attaches "\My Stats.xls" to the end
of values in textbox6. It works fine, accept when a user
selects only a drive and then clicks OK. For example, if
I were to select the C drive it puts 2 // in front and
this makes the path invalid(C:\\My Stats.xls), however it
works fine if I select a drive and then a folder.

TextBox6.Value = GetDirectory & "\My Stats.xls"

How should I fix this?
Thank you


Todd Huttenstine


Jake Marx[_3_]

File Path Problem
 
Hi Todd,

Something like this should work for you:

Sub demo()
Dim sDir As String

sDir = GetDirectory
If Right$(sDir, 1) = Application.PathSeparator Then _
sDir = Left$(sDir, Len(sDir) - 1)

TextBox6.Text = sDir & "\My Stats.xls"
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Todd Huttenstine wrote:
Below is a code that attaches "\My Stats.xls" to the end
of values in textbox6. It works fine, accept when a user
selects only a drive and then clicks OK. For example, if
I were to select the C drive it puts 2 // in front and
this makes the path invalid(C:\\My Stats.xls), however it
works fine if I select a drive and then a folder.

TextBox6.Value = GetDirectory & "\My Stats.xls"

How should I fix this?
Thank you


Todd Huttenstine


Todd Huttenstine[_2_]

File Path Problem
 
thanks, that worked great.

Todd Huttenstine
-----Original Message-----
Hi Todd,

Something like this should work for you:

Sub demo()
Dim sDir As String

sDir = GetDirectory
If Right$(sDir, 1) = Application.PathSeparator Then _
sDir = Left$(sDir, Len(sDir) - 1)

TextBox6.Text = sDir & "\My Stats.xls"
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address

unmonitored]


Todd Huttenstine wrote:
Below is a code that attaches "\My Stats.xls" to the end
of values in textbox6. It works fine, accept when a

user
selects only a drive and then clicks OK. For example,

if
I were to select the C drive it puts 2 // in front and
this makes the path invalid(C:\\My Stats.xls), however

it
works fine if I select a drive and then a folder.

TextBox6.Value = GetDirectory & "\My Stats.xls"

How should I fix this?
Thank you


Todd Huttenstine

.


Todd Huttenstine[_2_]

File Path Problem
 
thanks, that worked great.

Todd Huttenstine
-----Original Message-----
Hi Todd,

Something like this should work for you:

Sub demo()
Dim sDir As String

sDir = GetDirectory
If Right$(sDir, 1) = Application.PathSeparator Then _
sDir = Left$(sDir, Len(sDir) - 1)

TextBox6.Text = sDir & "\My Stats.xls"
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address

unmonitored]


Todd Huttenstine wrote:
Below is a code that attaches "\My Stats.xls" to the end
of values in textbox6. It works fine, accept when a

user
selects only a drive and then clicks OK. For example,

if
I were to select the C drive it puts 2 // in front and
this makes the path invalid(C:\\My Stats.xls), however

it
works fine if I select a drive and then a folder.

TextBox6.Value = GetDirectory & "\My Stats.xls"

How should I fix this?
Thank you


Todd Huttenstine

.



All times are GMT +1. The time now is 06:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com