Macro is not returning the correct value

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to remove a name of a specific file from its directory name, it's not the first time I've done it and I remember using the "Unbound" function last time but instead of the program returning the name to me of the specific file it is returning the number of the field corresponding to the file (5 in this case), can someone help me?


Code:

VBA Code:
Private Sub bt_file_Click()

Dim fd As Office.FileDialog
Dim strFile As String, strFile_extract() As String
 
Set fd = Application.FileDialog(msoFileDialogFilePicker)
 
With fd
 
    .Filters.Clear
    .Filters.Add "Excel Files", "*.xlsm", 1
    .Title = "Choose an Excel file"
    .AllowMultiSelect = False
 
    .InitialFileName = "C:\VBA Folder"
 
    If .Show = True Then
 
        strFile = .SelectedItems(1)
        strFile_extract = Split(strFile, "\")
        OtherBookPath = UBound(strFile_extract)
        MsgBox OtherBookPath
        
    End If

End With

Workbooks.Open Filename:=OtherBookPath

End Sub


Capturar.JPG
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Why are you trying to extract the file name from the path? You need the full path & file name in order to open it.
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top