{"id":4464,"date":"2023-07-10T22:03:02","date_gmt":"2023-07-10T22:03:02","guid":{"rendered":"https:\/\/statorials.org\/pt\/vba-verifica-se-o-arquivo-existe\/"},"modified":"2023-07-10T22:03:02","modified_gmt":"2023-07-10T22:03:02","slug":"vba-verifica-se-o-arquivo-existe","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/vba-verifica-se-o-arquivo-existe\/","title":{"rendered":"Como verificar se o arquivo existe usando vba (com exemplo)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Voc\u00ea pode usar a fun\u00e7\u00e3o <b>Dir<\/b> no VBA para verificar se existe um arquivo espec\u00edfico em uma pasta espec\u00edfica.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Aqui est\u00e1 uma maneira comum de usar esta afirma\u00e7\u00e3o na pr\u00e1tica:<\/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;\">Esta macro espec\u00edfica criar\u00e1 uma caixa de entrada onde o usu\u00e1rio pode inserir um caminho completo para um arquivo para verificar se ele existe.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Assim que o usu\u00e1rio inserir o caminho do arquivo, a macro produzir\u00e1 uma caixa de mensagem indicando se o arquivo existe ou n\u00e3o.<\/span><\/p>\n<p> <span style=\"color: #000000;\">O exemplo a seguir mostra como usar essa sintaxe na pr\u00e1tica.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Exemplo: verifique se o arquivo existe usando VBA<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Suponha que temos uma pasta localizada no seguinte local:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>C:\\Usu\u00e1rios\\bob\\Documentos\\dados_atual<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Esta pasta cont\u00e9m tr\u00eas arquivos CSV:<\/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;\">Digamos que queremos usar VBA para verificar se existe um arquivo chamado <strong>football_data.csv<\/strong> nesta pasta.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Podemos criar a seguinte macro para fazer isso:<\/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;\">Depois de executar esta macro, aparece uma caixa de entrada onde podemos inserir o caminho do arquivo:<\/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 verifica se o arquivo existe\" width=\"483\" height=\"309\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Inseriremos o caminho completo do arquivo <strong>football_data.csv<\/strong> :<\/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;\">Assim que clicarmos em <strong>OK<\/strong> , aparecer\u00e1 uma caixa de mensagem que nos informar\u00e1 se o arquivo existe na pasta que especificamos:<\/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;\">A caixa de mensagem nos informa que o arquivo existe.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : Voc\u00ea pode encontrar a documenta\u00e7\u00e3o completa da fun\u00e7\u00e3o <strong>Dir<\/strong> <a href=\"https:\/\/learn.microsoft.com\/en-us\/office\/vba\/language\/reference\/user-interface-help\/dir-function\" target=\"_blank\" rel=\"noopener\">aqui<\/a> .<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Os tutoriais a seguir explicam como realizar outras tarefas comuns em VBA:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/pt\/vba-criar-pasta\/\" target=\"_blank\" rel=\"noopener\">Como criar pastas usando VBA<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/vba-excluir-pasta\/\" target=\"_blank\" rel=\"noopener\">Como deletar pastas usando VBA<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/excluir-arquivo-vba\/\" target=\"_blank\" rel=\"noopener\">Como deletar arquivos usando VBA<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Voc\u00ea pode usar a fun\u00e7\u00e3o Dir no VBA para verificar se existe um arquivo espec\u00edfico em uma pasta espec\u00edfica. Aqui est\u00e1 uma maneira comum de usar esta afirma\u00e7\u00e3o na pr\u00e1tica: SubCheckFileExists () &#8216;ask user to type path to file InputFile = InputBox(&#8221; Check if this file exists: &#8220;) &#8216;check if file exists and output results [&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-4464","post","type-post","status-publish","format-standard","hentry","category-guia"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Como verificar se existe um arquivo usando VBA (com exemplo) - Estatologia<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como verificar se existe um arquivo usando VBA, com um exemplo.\" \/>\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\/pt\/vba-verifica-se-o-arquivo-existe\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como verificar se existe um arquivo usando VBA (com exemplo) - Estatologia\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como verificar se existe um arquivo usando VBA, com um exemplo.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/vba-verifica-se-o-arquivo-existe\/\" \/>\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. benjamim anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr. benjamim anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo estimado de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/vba-verifica-se-o-arquivo-existe\/\",\"url\":\"https:\/\/statorials.org\/pt\/vba-verifica-se-o-arquivo-existe\/\",\"name\":\"Como verificar se existe um arquivo usando VBA (com exemplo) - Estatologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-10T22:03:02+00:00\",\"dateModified\":\"2023-07-10T22:03:02+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como verificar se existe um arquivo usando VBA, com um exemplo.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/vba-verifica-se-o-arquivo-existe\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/vba-verifica-se-o-arquivo-existe\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/vba-verifica-se-o-arquivo-existe\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como verificar se o arquivo existe usando vba (com exemplo)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/pt\/#website\",\"url\":\"https:\/\/statorials.org\/pt\/\",\"name\":\"Statorials\",\"description\":\"O seu guia para a literacia estat\u00edstica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/pt\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-PT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\",\"name\":\"Dr. benjamim anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr. benjamim anderson\"},\"description\":\"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais\",\"sameAs\":[\"https:\/\/statorials.org\/pt\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Como verificar se existe um arquivo usando VBA (com exemplo) - Estatologia","description":"Este tutorial explica como verificar se existe um arquivo usando VBA, com um exemplo.","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\/pt\/vba-verifica-se-o-arquivo-existe\/","og_locale":"pt_PT","og_type":"article","og_title":"Como verificar se existe um arquivo usando VBA (com exemplo) - Estatologia","og_description":"Este tutorial explica como verificar se existe um arquivo usando VBA, com um exemplo.","og_url":"https:\/\/statorials.org\/pt\/vba-verifica-se-o-arquivo-existe\/","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. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"2 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/vba-verifica-se-o-arquivo-existe\/","url":"https:\/\/statorials.org\/pt\/vba-verifica-se-o-arquivo-existe\/","name":"Como verificar se existe um arquivo usando VBA (com exemplo) - Estatologia","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-10T22:03:02+00:00","dateModified":"2023-07-10T22:03:02+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como verificar se existe um arquivo usando VBA, com um exemplo.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/vba-verifica-se-o-arquivo-existe\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/vba-verifica-se-o-arquivo-existe\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/vba-verifica-se-o-arquivo-existe\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como verificar se o arquivo existe usando vba (com exemplo)"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/pt\/#website","url":"https:\/\/statorials.org\/pt\/","name":"Statorials","description":"O seu guia para a literacia estat\u00edstica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/pt\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-PT"},{"@type":"Person","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666","name":"Dr. benjamim anderson","image":{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr. benjamim anderson"},"description":"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais","sameAs":["https:\/\/statorials.org\/pt"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/4464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/comments?post=4464"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/4464\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=4464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=4464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=4464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}