{"id":123,"date":"2012-02-23T13:33:37","date_gmt":"2012-02-23T12:33:37","guid":{"rendered":"http:\/\/mariaevert.dk\/vba\/?p=123"},"modified":"2012-02-23T13:33:57","modified_gmt":"2012-02-23T12:33:57","slug":"check-extension-of-file","status":"publish","type":"post","link":"https:\/\/mariaevert.dk\/vba\/?p=123","title":{"rendered":"VBA &#8211; Check Extension of File"},"content":{"rendered":"<p>When looping through all files in a folder, it&#8217;s often necessary to check the extension of each file, so you only mess with Excel files, for example. <\/p>\n<p>The code below shows how to retrieve the extension of a file, define an array with &#8220;allowed&#8221; extensions, and match the extension of the file to the array. <\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n\r\nSub K\u00f8rImport()\r\n\r\nDim MinExtensionX\r\nDim Arr() As Variant\r\nDim lngLoc As Variant\r\n\r\n'Retrieve extension of file\r\nMinExtensionX = Mid(MyFile.Name, InStrRev(MyFile.Name, &quot;.&quot;) + 1)\r\n\r\nArr = Array(&quot;xls&quot;, &quot;xlsx&quot;) 'define which extensions you want to allow\r\nOn Error Resume Next\r\nlngLoc = Application.WorksheetFunction.Match(MinExtensionX, Arr(), 0)\r\nIf Not IsEmpty(lngLoc) Then ' \r\n\r\n'DO STUFF if it's an xls\/xlsx file. Otherwise, chose next file in folder\r\n\r\nEnd If\r\n\r\n\r\n     \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>When looping through all files in a folder, it&#8217;s often necessary to check the extension of each file, so you only mess with Excel files, for example. The code below shows how to retrieve the extension of a file, define an array with &#8220;allowed&#8221; extensions, and match the extension of the file to the array.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,5],"tags":[],"_links":{"self":[{"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/posts\/123"}],"collection":[{"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=123"}],"version-history":[{"count":8,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/posts\/123\/revisions"}],"predecessor-version":[{"id":131,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/posts\/123\/revisions\/131"}],"wp:attachment":[{"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}