Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Path command

I would like to store the path of a file in a variable. I have read
the help associated with Excel but I am not clear on the use of the
PATH command. I understand how to get the path of the current
workbook but what I want to do is to store the path of a file (which I
have obtained using the GETOPENFILENAME CODE) in a variable for later
use. Any suggestions?

Garry
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Path command

Sub test()
Dim strFile As String

strFile = Application.GetOpenFilename
If strFile = "False" Then Exit Sub

MsgBox strFile
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Garry" wrote in message
om...
I would like to store the path of a file in a variable. I have read
the help associated with Excel but I am not clear on the use of the
PATH command. I understand how to get the path of the current
workbook but what I want to do is to store the path of a file (which I
have obtained using the GETOPENFILENAME CODE) in a variable for later
use. Any suggestions?

Garry



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Path command

Rob,

Thanks for the reply but that wasn't exactly what I needed. I already
used code similar to what you suggested to get the full path name,
including filename. What I need is to find the actual path, without
the filename. I need to iteratively retrieve files in the same
directory as one located by the code you suggested. I want to capture
the path alone then concatenate various filenames to that path.

Garry

"Rob van Gelder" wrote in message ...
Sub test()
Dim strFile As String

strFile = Application.GetOpenFilename
If strFile = "False" Then Exit Sub

MsgBox strFile
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Garry" wrote in message
om...
I would like to store the path of a file in a variable. I have read
the help associated with Excel but I am not clear on the use of the
PATH command. I understand how to get the path of the current
workbook but what I want to do is to store the path of a file (which I
have obtained using the GETOPENFILENAME CODE) in a variable for later
use. Any suggestions?

Garry

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Path command

Here's yet another path extractor (there was a conversation about this the
other day.
Keep in mind there are easier ways to do this depending on your version of
Excel.

Sub test()
Dim strFile As String, strPath As String, i As Long, j As Long

strFile = "C:\windows\system32\drivers\etc\HOSTS"

i = InStr(1, strFile, Application.PathSeparator): j = 1
Do Until i = 0: j = i: i = InStr(i + 1, strFile,
Application.PathSeparator): Loop
strPath = Mid(strFile, 1, j)

MsgBox strPath
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Garry" wrote in message
m...
Rob,

Thanks for the reply but that wasn't exactly what I needed. I already
used code similar to what you suggested to get the full path name,
including filename. What I need is to find the actual path, without
the filename. I need to iteratively retrieve files in the same
directory as one located by the code you suggested. I want to capture
the path alone then concatenate various filenames to that path.

Garry

"Rob van Gelder" wrote in message

...
Sub test()
Dim strFile As String

strFile = Application.GetOpenFilename
If strFile = "False" Then Exit Sub

MsgBox strFile
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Garry" wrote in message
om...
I would like to store the path of a file in a variable. I have read
the help associated with Excel but I am not clear on the use of the
PATH command. I understand how to get the path of the current
workbook but what I want to do is to store the path of a file (which I
have obtained using the GETOPENFILENAME CODE) in a variable for later
use. Any suggestions?

Garry



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Path command

Rob,

Thanks for the information. I'll give this a try. I used a mid
function after retrieving the full name with the GetOpenFileName
method. I had hoped there was a more straight forward way to do it.
You plan looks better, even though not much less complex.

Thanks again,

Garry


"Rob van Gelder" wrote in message ...
Here's yet another path extractor (there was a conversation about this the
other day.
Keep in mind there are easier ways to do this depending on your version of
Excel.

Sub test()
Dim strFile As String, strPath As String, i As Long, j As Long

strFile = "C:\windows\system32\drivers\etc\HOSTS"

i = InStr(1, strFile, Application.PathSeparator): j = 1
Do Until i = 0: j = i: i = InStr(i + 1, strFile,
Application.PathSeparator): Loop
strPath = Mid(strFile, 1, j)

MsgBox strPath
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Garry" wrote in message
m...
Rob,

Thanks for the reply but that wasn't exactly what I needed. I already
used code similar to what you suggested to get the full path name,
including filename. What I need is to find the actual path, without
the filename. I need to iteratively retrieve files in the same
directory as one located by the code you suggested. I want to capture
the path alone then concatenate various filenames to that path.

Garry

"Rob van Gelder" wrote in message

...
Sub test()
Dim strFile As String

strFile = Application.GetOpenFilename
If strFile = "False" Then Exit Sub

MsgBox strFile
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Garry" wrote in message
om...
I would like to store the path of a file in a variable. I have read
the help associated with Excel but I am not clear on the use of the
PATH command. I understand how to get the path of the current
workbook but what I want to do is to store the path of a file (which I
have obtained using the GETOPENFILENAME CODE) in a variable for later
use. Any suggestions?

Garry



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Path command

I really liked the code that Rob posted - it covers EVERYTHING.

I typically use the following which is far less sophisticated but
hasn't failed me yet:

Sub test()
Dim strFile As String, strPath As String, strEndofPath As String

strFile = Application.GetOpenFilename
strEndofPath = InStr(strFile, Dir(strFile)) - 2
strPath = Mid(strFile, 1, strEndofPath)

MsgBox strPath
End Sub




Sub test()
Dim strFile As String, strPath As String, i As Long, j As Long

strFile = "C:\windows\system32\drivers\etc\HOSTS"

i = InStr(1, strFile, Application.PathSeparator): j = 1
Do Until i = 0: j = i: i = InStr(i + 1, strFile,
Application.PathSeparator): Loop
strPath = Mid(strFile, 1, j)

MsgBox strPath
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
File Path Too Long? Not Anymore! Check out Long Path Tool Max Loger Excel Discussion (Misc queries) 1 March 24th 17 07:59 AM
Formula too long - new file path is shorter than old file path - Excel 2003 Greg J Excel Worksheet Functions 1 November 22nd 06 05:16 PM
hyperlink navigation path path wrong in Excel 2003 CE Admin Excel Discussion (Misc queries) 5 January 7th 06 07:47 PM
how to change absolute path to relative path hwijgerse Excel Worksheet Functions 0 November 25th 05 07:18 AM
Can the user "Choose" the path via a VBA command? Brad Patterson Excel Programming 3 August 15th 03 04:24 PM


All times are GMT +1. The time now is 03:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"