kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
This code here get me only the name of the selected file with its extension.
When I change the line
To this
It adds the name of the file and it's extension to the path name.
Now what I want to do is to get the path name only up to the last path separator . I have been digging around for a while now but can't seem to find out how to yet.
I need a hand with that. Thanks
Code:
[COLOR=#0C0D0E][FONT='inherit'][FONT=inherit]<code style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; vertical-align: baseline; max-height: 300px; overflow: auto;">[COLOR=#101094]Sub[/COLOR][COLOR=#303336] GetFilePath[/COLOR][COLOR=#303336]()[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Set[/COLOR][COLOR=#303336] myFile [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] Application[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]FileDialog[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]msoFileDialogOpen[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336] myFile
[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Title [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]"Choose File"[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]AllowMultiSelect [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]False[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Show [/COLOR][COLOR=#303336]<>[/COLOR][COLOR=#303336]-[/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#101094]Then[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Exit[/COLOR][COLOR=#101094]Sub[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336]
FileSelected [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] Replace[/COLOR][COLOR=#303336](.[/COLOR][COLOR=#303336]SelectedItems[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336]),[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]InitialFileName[/COLOR][COLOR=#303336],[/COLOR][COLOR=#7D2727]""[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#303336]MsgBox FileSelected
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]Sub
[/COLOR]</code>[/FONT][/FONT][/COLOR]
When I change the line
Code:
[COLOR=#303336][FONT=Consolas]FileSelected [/FONT][/COLOR][COLOR=#303336][FONT=Consolas]=[/FONT][/COLOR][COLOR=#303336][FONT=Consolas] Replace[/FONT][/COLOR][COLOR=#303336][FONT=Consolas](.[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]SelectedItems[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]([/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas]1[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]),[/FONT][/COLOR][COLOR=#303336][FONT=Consolas].[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]InitialFileName[/FONT][/COLOR][COLOR=#303336][FONT=Consolas],[/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas]""[/FONT][/COLOR][COLOR=#303336][FONT=Consolas])[/FONT][/COLOR]
To this
Code:
[COLOR=#303336][FONT=Consolas]FileSelected [/FONT][/COLOR][COLOR=#303336][FONT=Consolas]=[/FONT][/COLOR][COLOR=#303336][FONT=Consolas].[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]SelectedItems[/FONT][/COLOR][COLOR=#303336][FONT=Consolas]([/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas]1[/FONT][/COLOR][COLOR=#303336][FONT=Consolas])[/FONT][/COLOR]
It adds the name of the file and it's extension to the path name.
Now what I want to do is to get the path name only up to the last path separator . I have been digging around for a while now but can't seem to find out how to yet.
I need a hand with that. Thanks