{"id":4465,"date":"2023-07-10T22:03:02","date_gmt":"2023-07-10T22:03:02","guid":{"rendered":"https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/"},"modified":"2023-07-10T22:03:02","modified_gmt":"2023-07-10T22:03:02","slug":"vba-controleert-of-het-bestand-bestaat","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/","title":{"rendered":"Controleren of een bestand bestaat met vba (met voorbeeld)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">U kunt de <b>Dir-<\/b> functie in VBA gebruiken om te controleren of een specifiek bestand in een specifieke map bestaat.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Hier is een gebruikelijke manier om deze verklaring in de praktijk te gebruiken:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #0000ff;\">SubCheckFileExists<\/span> ()\n\n<span style=\"color: #008000;\">'ask user to type path to file\n<\/span>InputFile = InputBox(\" <span style=\"color: #ff0000;\">Check if this file exists:<\/span> \")\n\n<span style=\"color: #008000;\">'check if file exists and output results to message box\n<\/span><span style=\"color: #0000ff;\">If<\/span> Dir(InputFile) &lt;&gt; \"\" <span style=\"color: #0000ff;\">Then<\/span>\n    MsgBox \u201c <span style=\"color: #ff0000;\">This File Exists<\/span> \u201d\n<span style=\"color: #0000ff;\">Else<\/span>\n    MsgBox \u201c <span style=\"color: #ff0000;\">This File Does Not Exist<\/span> \u201d\n<span style=\"color: #0000ff;\">End If<\/span>\n\n<span style=\"color: #0000ff;\">End Sub\n<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Deze specifieke macro cre\u00ebert een invoervak waarin de gebruiker een volledig pad naar een bestand kan invoeren om te controleren of het bestaat.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Zodra de gebruiker het bestandspad invoert, produceert de macro een berichtvenster waarin wordt aangegeven of het bestand bestaat of niet.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Het volgende voorbeeld laat zien hoe u deze syntaxis in de praktijk kunt gebruiken.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Voorbeeld: Controleer of het bestand bestaat met VBA<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Stel dat we een map hebben op de volgende locatie:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>C:\\Gebruikers\\bob\\Documenten\\huidige_data<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Deze map bevat drie CSV-bestanden:<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-34624 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/delfiles1.jpg\" alt=\"\" width=\"548\" height=\"381\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Laten we zeggen dat we VBA willen gebruiken om te controleren of er een bestand met de naam <strong>voetbal_data.csv<\/strong> in deze map bestaat.<\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen hiervoor de volgende macro maken:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #0000ff;\">SubCheckFileExists<\/span> ()\n\n<span style=\"color: #008000;\">'ask user to type path to file\n<\/span>InputFile = InputBox(\" <span style=\"color: #ff0000;\">Check if this file exists:<\/span> \")\n\n<span style=\"color: #008000;\">'check if file exists and output results to message box\n<\/span><span style=\"color: #0000ff;\">If<\/span> Dir(InputFile) &lt;&gt; \"\" <span style=\"color: #0000ff;\">Then<\/span>\n    MsgBox \u201c <span style=\"color: #ff0000;\">This File Exists<\/span> \u201d\n<span style=\"color: #0000ff;\">Else<\/span>\n    MsgBox \u201c <span style=\"color: #ff0000;\">This File Does Not Exist<\/span> \u201d\n<span style=\"color: #0000ff;\">End If<\/span>\n\n<span style=\"color: #0000ff;\">End Sub<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Zodra we deze macro uitvoeren, verschijnt er een invoervak waarin we het bestandspad kunnen invoeren:<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-34937\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/exi1.png\" alt=\"VBA controleert of het bestand bestaat\" width=\"483\" height=\"309\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">We voeren het volledige pad van het bestand <strong>voetbal_data.csv<\/strong> in:<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-34938 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/exi2.png\" alt=\"\" width=\"554\" height=\"351\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Zodra we op <strong>OK<\/strong> klikken, verschijnt er een berichtvenster waarin staat of het bestand bestaat in de map die we hebben opgegeven:<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-34939 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/exi3.png\" alt=\"\" width=\"450\" height=\"347\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Het berichtvenster vertelt ons dat het bestand bestaat.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Opmerking<\/strong> : u kunt de volledige documentatie voor de <strong>Dir-<\/strong> functie <a href=\"https:\/\/learn.microsoft.com\/en-us\/office\/vba\/language\/reference\/user-interface-help\/dir-function\" target=\"_blank\" rel=\"noopener\">hier<\/a> vinden.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">In de volgende tutorials wordt uitgelegd hoe u andere veelvoorkomende taken in VBA kunt uitvoeren:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/vba-map-aanmaken\/\" target=\"_blank\" rel=\"noopener\">Mappen maken met VBA<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/vba-verwijdermap\/\" target=\"_blank\" rel=\"noopener\">Hoe mappen te verwijderen met VBA<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/vba-bestand-verwijderen\/\" target=\"_blank\" rel=\"noopener\">Hoe bestanden te verwijderen met VBA<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>U kunt de Dir- functie in VBA gebruiken om te controleren of een specifiek bestand in een specifieke map bestaat. Hier is een gebruikelijke manier om deze verklaring in de praktijk te gebruiken: SubCheckFileExists () &#8218;ask user to type path to file InputFile = InputBox(&#8220; Check if this file exists: &#8222;) &#8218;check if file exists [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-4465","post","type-post","status-publish","format-standard","hentry","category-gids"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Controleren of een bestand bestaat met VBA (met voorbeeld) - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt met een voorbeeld uitgelegd hoe u kunt controleren of een bestand bestaat met behulp van VBA.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Controleren of een bestand bestaat met VBA (met voorbeeld) - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt met een voorbeeld uitgelegd hoe u kunt controleren of een bestand bestaat met behulp van VBA.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-10T22:03:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/delfiles1.jpg\" \/>\n<meta name=\"author\" content=\"Dr.benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr.benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"2\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/\",\"url\":\"https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/\",\"name\":\"Controleren of een bestand bestaat met VBA (met voorbeeld) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-10T22:03:02+00:00\",\"dateModified\":\"2023-07-10T22:03:02+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt met een voorbeeld uitgelegd hoe u kunt controleren of een bestand bestaat met behulp van VBA.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Controleren of een bestand bestaat met vba (met voorbeeld)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/nl\/#website\",\"url\":\"https:\/\/statorials.org\/nl\/\",\"name\":\"Statorials\",\"description\":\"Uw gids voor statistische competentie\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/nl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\",\"name\":\"Dr.benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr.benjamin anderson\"},\"description\":\"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder\",\"sameAs\":[\"http:\/\/statorials.org\/nl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Controleren of een bestand bestaat met VBA (met voorbeeld) - Statorials","description":"In deze tutorial wordt met een voorbeeld uitgelegd hoe u kunt controleren of een bestand bestaat met behulp van VBA.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/","og_locale":"de_DE","og_type":"article","og_title":"Controleren of een bestand bestaat met VBA (met voorbeeld) - Statorials","og_description":"In deze tutorial wordt met een voorbeeld uitgelegd hoe u kunt controleren of een bestand bestaat met behulp van VBA.","og_url":"https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/","og_site_name":"Statorials","article_published_time":"2023-07-10T22:03:02+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/delfiles1.jpg"}],"author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"2\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/","url":"https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/","name":"Controleren of een bestand bestaat met VBA (met voorbeeld) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-10T22:03:02+00:00","dateModified":"2023-07-10T22:03:02+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt met een voorbeeld uitgelegd hoe u kunt controleren of een bestand bestaat met behulp van VBA.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/vba-controleert-of-het-bestand-bestaat\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Controleren of een bestand bestaat met vba (met voorbeeld)"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/nl\/#website","url":"https:\/\/statorials.org\/nl\/","name":"Statorials","description":"Uw gids voor statistische competentie","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/nl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de"},{"@type":"Person","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219","name":"Dr.benjamin anderson","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/","url":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr.benjamin anderson"},"description":"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder","sameAs":["http:\/\/statorials.org\/nl"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/4465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/comments?post=4465"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/4465\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=4465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=4465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=4465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}