Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tom tom is offline
external usenet poster
 
Posts: 570
Default Help in Getting the File Name from a path

I have created the following macros and function to import a file and then
extract just the path name. Problem is that the function returns the entire
path name and not just the file mane. The importation of the file works fine.
Below is the code I wrote, any suggestions for a fix?

Dim myFileName As Variant

Sub ImportRunData()
ImportDisplayRDFile
stFullName = myFileName
GetFileName (stFullName)
End Sub
----------------------------------------------
Sub ImportDisplayRDFile()
'
'ImportRunDataFile Macro
'
myFileName = Application.GetOpenFilename(FileFilter:="Text Files, *.csv")
If myFileName = False Then
Exit Sub 'user hit cancle
End If
Sheets("Sheet1").Select
With ActiveSheet
With .QueryTables.Add(Connection:="Text;" & myFileName,
Destination:=.Range("$AG$1"))
.Name = "Pick Place for JRB001078B DDU"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Sheets("Sheet1").Select
Range("E3").Select
End With
End Sub
----------------------------------------
Function GetFileName(stFullName As String) As String
'GetFileName returns the file name from the end of a full path namme
'stFullName is returned if no path seperator is found
Dim stPathSep As String 'Path Separator Character
Dim iFNLength As Integer 'Length of stFullName
Dim i As Integer
stPathSep = Application.PathSeparator
iFNLength = Len(stFullName)
stFullName = myFileName
'Find last path separator character, if there is one
For i = iFNLength To 1 Step -1
If Mid(stFullName, i, 1) = stPathSep Then Exit For
Next i
GetFileName = Right(stFullName, iFNLength - 1)
Range("C5") = GetFileName
End Function
-----------------------------------------------------------------

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Help in Getting the File Name from a path

Function GetFileName(stFullName As String) As String
GetFileName = Right$(stFullName, Len(stFullName) - InStrRev(stFullName,
Application.PathSeparator))
End Function



--
__________________________________
HTH

Bob

"Tom" wrote in message
...
I have created the following macros and function to import a file and then
extract just the path name. Problem is that the function returns the
entire
path name and not just the file mane. The importation of the file works
fine.
Below is the code I wrote, any suggestions for a fix?

Dim myFileName As Variant

Sub ImportRunData()
ImportDisplayRDFile
stFullName = myFileName
GetFileName (stFullName)
End Sub
----------------------------------------------
Sub ImportDisplayRDFile()
'
'ImportRunDataFile Macro
'
myFileName = Application.GetOpenFilename(FileFilter:="Text Files,
*.csv")
If myFileName = False Then
Exit Sub 'user hit cancle
End If
Sheets("Sheet1").Select
With ActiveSheet
With .QueryTables.Add(Connection:="Text;" & myFileName,
Destination:=.Range("$AG$1"))
.Name = "Pick Place for JRB001078B DDU"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1,
1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Sheets("Sheet1").Select
Range("E3").Select
End With
End Sub
----------------------------------------
Function GetFileName(stFullName As String) As String
'GetFileName returns the file name from the end of a full path namme
'stFullName is returned if no path seperator is found
Dim stPathSep As String 'Path Separator Character
Dim iFNLength As Integer 'Length of stFullName
Dim i As Integer
stPathSep = Application.PathSeparator
iFNLength = Len(stFullName)
stFullName = myFileName
'Find last path separator character, if there is one
For i = iFNLength To 1 Step -1
If Mid(stFullName, i, 1) = stPathSep Then Exit For
Next i
GetFileName = Right(stFullName, iFNLength - 1)
Range("C5") = GetFileName
End Function
-----------------------------------------------------------------



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Help in Getting the File Name from a path

Function GetFileName(strFullName As String) As String
GetFileName = Mid(strFullName, InStrRev(strFullName,
Application.PathSeparator) + 1)
End Function

--
If this post helps click Yes
---------------
Jacob Skaria


"Tom" wrote:

I have created the following macros and function to import a file and then
extract just the path name. Problem is that the function returns the entire
path name and not just the file mane. The importation of the file works fine.
Below is the code I wrote, any suggestions for a fix?

Dim myFileName As Variant

Sub ImportRunData()
ImportDisplayRDFile
stFullName = myFileName
GetFileName (stFullName)
End Sub
----------------------------------------------
Sub ImportDisplayRDFile()
'
'ImportRunDataFile Macro
'
myFileName = Application.GetOpenFilename(FileFilter:="Text Files, *.csv")
If myFileName = False Then
Exit Sub 'user hit cancle
End If
Sheets("Sheet1").Select
With ActiveSheet
With .QueryTables.Add(Connection:="Text;" & myFileName,
Destination:=.Range("$AG$1"))
.Name = "Pick Place for JRB001078B DDU"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Sheets("Sheet1").Select
Range("E3").Select
End With
End Sub
----------------------------------------
Function GetFileName(stFullName As String) As String
'GetFileName returns the file name from the end of a full path namme
'stFullName is returned if no path seperator is found
Dim stPathSep As String 'Path Separator Character
Dim iFNLength As Integer 'Length of stFullName
Dim i As Integer
stPathSep = Application.PathSeparator
iFNLength = Len(stFullName)
stFullName = myFileName
'Find last path separator character, if there is one
For i = iFNLength To 1 Step -1
If Mid(stFullName, i, 1) = stPathSep Then Exit For
Next i
GetFileName = Right(stFullName, iFNLength - 1)
Range("C5") = GetFileName
End Function
-----------------------------------------------------------------

  #4   Report Post  
Posted to microsoft.public.excel.programming
tom tom is offline
external usenet poster
 
Posts: 570
Default Help in Getting the File Name from a path

Bob,

Thank you for the help, it worked just fine.

"Bob Phillips" wrote:

Function GetFileName(stFullName As String) As String
GetFileName = Right$(stFullName, Len(stFullName) - InStrRev(stFullName,
Application.PathSeparator))
End Function



--
__________________________________
HTH

Bob

"Tom" wrote in message
...
I have created the following macros and function to import a file and then
extract just the path name. Problem is that the function returns the
entire
path name and not just the file mane. The importation of the file works
fine.
Below is the code I wrote, any suggestions for a fix?

Dim myFileName As Variant

Sub ImportRunData()
ImportDisplayRDFile
stFullName = myFileName
GetFileName (stFullName)
End Sub
----------------------------------------------
Sub ImportDisplayRDFile()
'
'ImportRunDataFile Macro
'
myFileName = Application.GetOpenFilename(FileFilter:="Text Files,
*.csv")
If myFileName = False Then
Exit Sub 'user hit cancle
End If
Sheets("Sheet1").Select
With ActiveSheet
With .QueryTables.Add(Connection:="Text;" & myFileName,
Destination:=.Range("$AG$1"))
.Name = "Pick Place for JRB001078B DDU"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1,
1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Sheets("Sheet1").Select
Range("E3").Select
End With
End Sub
----------------------------------------
Function GetFileName(stFullName As String) As String
'GetFileName returns the file name from the end of a full path namme
'stFullName is returned if no path seperator is found
Dim stPathSep As String 'Path Separator Character
Dim iFNLength As Integer 'Length of stFullName
Dim i As Integer
stPathSep = Application.PathSeparator
iFNLength = Len(stFullName)
stFullName = myFileName
'Find last path separator character, if there is one
For i = iFNLength To 1 Step -1
If Mid(stFullName, i, 1) = stPathSep Then Exit For
Next i
GetFileName = Right(stFullName, iFNLength - 1)
Range("C5") = GetFileName
End Function
-----------------------------------------------------------------




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
http://CannotDeleteFile.net - Cannot Delete File? Try Long Path ToolFilename is too long? Computer Complaining Your Filename Is Too Long? TheLong Path Tool Can Help While most people can go about their businessblissfully unaware of the Windo Max Loger Excel Discussion (Misc queries) 0 June 14th 11 04:30 PM
Creating Excel file that points to relative path .cub file NewUser1 Excel Programming 0 January 11th 08 03:59 PM
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
How set file open path to filepath of file opened with Explorer ? RandyDtg1 Excel Programming 0 May 14th 04 02:05 AM


All times are GMT +1. The time now is 05:52 AM.

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

About Us

"It's about Microsoft Excel"