Find file and remove .csv extension
If I follow ...
'Option Explicit
Sub Test()
Dim Filter As String, Caption As String, DestinationFile As String
Dim SelectedFile As Variant
Filter = "Text files (*.csv),*.csv"
Caption = "Please Select a File " '' & TheUser ''< ?
SelectedFile = Application.GetOpenFilename(Filter, , Caption)
If VarType(SelectedFile) = vbBoolean Then
MsgBox "user cancelled"
Else
On Error Resume Next
DestinationFile = SelectedFile
Mid(DestinationFile, Len(DestinationFile) - 2, 3) = "txt"
Debug.Print SelectedFile
Debug.Print DestinationFile
Name SelectedFile As DestinationFile
If Err.Number Then
MsgBox Err.Description, , "Error renaming file"
End If
On Error GoTo 0
End If
End Sub
Regards,
Peter T
"Rob" wrote in message
...
Hi,
I'm tring to open a window, select a file with CSV extension, the file is
coded to SelectedFile and then remove I want to remove the .CSV before
renaming the file with the same name albeit with a .TXT extension.
I've tried the code below for the inital test but it fails on the
WorksheetFunction code.
Am I on the right track?
Thanks, Rob
Sub macro1()
Dim Filter, Caption, SelectedFile, DestinationFile As String
Filter = "Text files (*.csv),*.csv"
Caption = "Please Select a File " & TheUser
SelectedFile = Application.GetOpenFilename(Filter, , Caption)
SelectedFile = Application.WorksheetFunction _
.Left(SelectedFile, Find(".CSV", (.Upper(SelectedFile)), 1) - 1)
Debug.Print SelectedFile
End Sub
|