GetOpenFilename

T

Todd Htutenstine

below is the code I have used to to open the open file
dialog and display on Excel type files. It works
correctly, however if I select and open a file in the
dialog box, I want combobox3 to show ONLY the filename,
NOT the file name including path. Currently the below
code shows the full path in combobox3.
How do I do this?

If ComboBox3.Value = "Export from Un-Opened Workbook..."
Then
'MsgBox ("Navigate to source workbook and then click "
& "OK")
FileToOpen = Application _
.GetOpenFilename("All Microsoft Excel Files
(*.xl;*.xls;*.xla;*.xlt;*.xlm;*.xlc;*.xlw;*.xll;*.xlb),*.xl
;*.xls;*.xla;*.xlt;*.xlm;*.xlc;*.xlw;*.xll;*.xlb,Excel
Files (*.xls),*.xls,Add-In Files (*.xla),*.xla")
If FileToOpen = False Then
GoTo SelectWorkbook
Else
Workbooks.Open FileToOpen
Unload Me
PublishBackupExport.Show
ComboBox3.Value = ComboBox3.Value
GoTo SelectWorkbook
End If
End If


Thank you
Todd Huttenstine
 
F

Frank Kabel

Hi
have a look at the InStrRev method. Use this to find the
last '\' in your return value and use Mid/Right to get
only the relevant part (Works for Excel 2000+)
 
T

Todd Htutenstine

I used the below code:

If ComboBox3.Value = "Export from Un-Opened Workbook..."
Then
'MsgBox ("Navigate to source workbook and then click "
& "OK")
FileToOpen = Application _
.GetOpenFilename("All Microsoft Excel Files
(*.xl;*.xls;*.xla;*.xlt;*.xlm;*.xlc;*.xlw;*.xll;*.xlb),*.xl
;*.xls;*.xla;*.xlt;*.xlm;*.xlc;*.xlw;*.xll;*.xlb,Excel
Files (*.xls),*.xls,Add-In Files (*.xla),*.xla")
If FileToOpen = False Then
GoTo SelectWorkbook
Else
Workbooks.Open FileToOpen
ComboBox3.AddItem ActiveWorkbook.Name
ComboBox3.Value = ActiveWorkbook.Name
End If
End If

I will also look at the InStrRev as you suggested. Thank
you. There are mahy times when I need to do that sort of
thing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top