Hello all,
I am searching for a vba code to open all xls files in a folder if the name of these files contains a specific text. It would be great to ask me when name i am searching, when run the vba.
I made one that opens all files, but...
I am searching for a vba code to open all xls files in a folder if the name of these files contains a specific text. It would be great to ask me when name i am searching, when run the vba.
I made one that opens all files, but...
Code:
Sub OpenFiles()
<code spellcheck="false" class="listtype-code listindent1 list-code1">Dim MyFolder As String</code>
<code spellcheck="false" class="listtype-code listindent1 list-code1">Dim MyFile As String</code>
<code spellcheck="false" class="listtype-code listindent1 list-code1">
</code>
<code spellcheck="false" class="listtype-code listindent1 list-code1">MyFolder = "C:\Users\xxx\Desktop\New folder\"</code>
<code spellcheck="false" class="listtype-code listindent1 list-code1">MyFile = Dir(MyFolder & "\*.xls")</code>
<code spellcheck="false" class="listtype-code listindent1 list-code1">
</code>
<code spellcheck="false" class="listtype-code listindent1 list-code1">Do Until MyFile = ""</code>
<code spellcheck="false" class="listtype-code listindent1 list-code1"> Workbooks.Open Filename:=MyFolder & "" & MyFile</code>
<code spellcheck="false" class="listtype-code listindent1 list-code1"> MyFile = Dir</code>
<code spellcheck="false" class="listtype-code listindent1 list-code1">Loop</code>
End Sub