Just ask the file system for the first matching file: Dim path As String: path = ThisWorkbook.path & ' Peach Apple ' FindFirstFile = Dir$(path & '.xlsm') If (FindFirstFile ') Then Workbooks.Open path & FindFirstFile Else '// not found End If.
How do I open a SharePoint file using part of the filename?
I have a file that is updated every year (Demand 2016, Demand 2017 etc.)
I currently link the file with the SharePoint url.
I want to find the file with 'Demand' in the name.
Community♦
JazJaz
1 Answer
With the help of the comments above, I found a solution that worked. Below is the code to cycle through filenames in a SharePoint root directory and open a file that is similar to a string name
cxw13.2k22 gold badges2525 silver badges5757 bronze badges
JazJaz
Not the answer you're looking for? Browse other questions tagged excelvbasharepointpattern-matchingfilenames or ask your own question.
I am trying to get Excel to open any file in the a given folder
(ThisWorkbook.PathPeachApple)
that has .xlsm extension (there is always only 1 file). Is it possible to open it with wildcard character? I do not know the name of the file, just the extension.If not, is there a way to do it?
Community♦
user628797user628797
![Chemsherpa ai Chemsherpa ai](/uploads/1/2/4/9/124952259/786277615.jpg)
4 Answers
Just ask the file system for the first matching file:
(This will not search sub-directories)
Alex K.Alex K.143k2323 gold badges210210 silver badges247247 bronze badges
You mentioned that it would be nice addition to open last modified file or file with shortest name, so let's start - there's a code example how you can grab all three files (first finded, last modified, with shortest name). You can modify this as you wish (add some parameters, add error handling, return only specified, etc).
CommonSenseCommonSense3,02022 gold badges77 silver badges2828 bronze badges
Try the code below, it will open your '*.xlsm' file, in the path you've requested.
Shai RadoShai Rado29.9k77 gold badges1616 silver badges3333 bronze badges
PFB for the code required for opening the macro file with extension(.xlsm).
Ramandeep SinghRamandeep Singh