I am working on a code in Excel VBA, where the user can pick the default route of a file if it is not on its default path.
I would like to filter it, to make sure that they will not select a wrong file.
My idea is to filter it somehow to check if the "original filename" (that you can see in properties -> details) is the same as the one I give. This way it would work even if the specific file is renamed.
My problem is, that I don't know how to refer to it.
Edit
Thanks to ZAT, the actual code looks like this:
Private Sub vncexe(vncexe As String)
Dim vncpath1 As String
Dim vncpath2 As String
Static temppath As String
vncpath1 = "C:\Program Files\RealVNC\VNC Viewer\vncviewer.exe"
vncpath2 = "C:\Program Files\RealVNC\VNC4\vncviewer.exe"
Dim opt As String
ob opt
If opt = "ob1" Then
If Dir(vncpath1) <> "" Then
vncexe = vncpath1
ElseIf Dir(vncpath2) <> "" Then
vncexe = vncpath2
ElseIf temppath <> "" Then
vncexe = temppath
Else
MsgBox "VNC viewer exe not on default path"
start:
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Please select VNC viewer"
.InitialView = msoFileDialogViewSmallIcons
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "VNCviewer.exe", "*.exe"
.Show
If .SelectedItems.Count <> 1 Then 'here should the "OR <> [original filename]" be
End
Else
vncexe = .SelectedItems(1)
strVNC = Right(vncexe, 13)
If strVNC = "vncviewer.exe" Then
temppath = vncexe
Else
MsgBox "wrong file selected"
temppath = ""
GoTo start
End If
End If
End With
End If
End If
End Sub
The original file path is already set to a default "vncpath1" and "vncpath2".
temppath is a string that gets the new path that we set manually here with this script if the file was not found on "vncpath1" and "vncpath2"
but my question was, if there is a way, to get the "original filename" of the selected exe and filter it, so it would work only if it is (in this case) "vncviewer.exe"
so even if I rename the file, the "original filename" property remains "vncviewer.exe"
thanks again to ZET the only problem with the code now is if the vncviewer.exe was renamed for example to vnc.exe, it will not work, this is why I need to get the "original filename" property.
And because I like to work fancy :-)