{"id":940,"date":"2020-12-02T17:09:51","date_gmt":"2020-12-02T17:09:51","guid":{"rendered":"http:\/\/www.vbastring.com\/blog\/?p=940"},"modified":"2020-12-02T17:55:34","modified_gmt":"2020-12-02T17:55:34","slug":"how-to-load-a-text-file-in-excel-vba-with-load-data-infile","status":"publish","type":"post","link":"https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/","title":{"rendered":"How To Load A Text File In Excel VBA With Load Data Infile"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2020\/12\/LOAD-TEXT-FILE.png?resize=877%2C589\" alt=\"\" width=\"877\" height=\"589\" class=\"aligncenter size-full wp-image-948\" \/><\/p>\n<p>So for reference sake, here is something easy.<\/p>\n<p>This is how to load a local text file into a variable, so you can process it.<\/p>\n<p>For example: <\/p>\n<p>So you have some <a href=\"http:\/\/www.vbastring.com\/blog\/how-to-parse-json-with-excel-vba\/\" rel=\"noopener noreferrer\" target=\"_blank\">JSON file<\/a>, and you put the <a href=\"http:\/\/www.vbastring.com\/blog\/how-to-parse-json-with-excel-vba\/\" rel=\"noopener noreferrer\" target=\"_blank\">JSON <\/a>formatted text locally in a text file so you can experiment on parsing it before you actually run a lot of web queries.<\/p>\n<p>Well here is how to do it:<\/p>\n<pre class=\"lang:vb decode:true \" >\r\nSub LoadFile()\r\n    Dim strURL As String\r\n    \r\n    'this is the text file in the directory of your spreadsheet   \r\n    strURL = ThisWorkbook.Path &amp; \"\\currencies.txt\"\r\n    \r\n    Dim strFileContent As String\r\n    Dim intFile As Integer\r\n    \r\n    intFile = FreeFile\r\n    Open strURL For Input As #intFile\r\n    strFileContent = Input(LOF(intFile), intFile)\r\n    Close intFile\r\n\r\nEnd Sub\r\n<\/pre>\n<p>Now the contents of your text file are in the string <strong>strFileContent<\/strong>.<\/p>\n<p>Questions?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So for reference sake, here is something easy. This is how to load a local text file into a variable, so you can process it. For example: So you have some JSON file, and you put the JSON formatted text locally in a text file so you can experiment on parsing it before you actually [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","om_disable_all_campaigns":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-940","post","type-post","status-publish","format-standard","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How To Load A Text File In Excel VBA With Load Data Infile - My Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Load A Text File In Excel VBA With Load Data Infile - My Blog\" \/>\n<meta property=\"og:description\" content=\"So for reference sake, here is something easy. This is how to load a local text file into a variable, so you can process it. For example: So you have some JSON file, and you put the JSON formatted text locally in a text file so you can experiment on parsing it before you actually [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/\" \/>\n<meta property=\"og:site_name\" content=\"My Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-02T17:09:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-12-02T17:55:34+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2020\/12\/LOAD-TEXT-FILE.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/12\\\/02\\\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/12\\\/02\\\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\"},\"headline\":\"How To Load A Text File In Excel VBA With Load Data Infile\",\"datePublished\":\"2020-12-02T17:09:51+00:00\",\"dateModified\":\"2020-12-02T17:55:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/12\\\/02\\\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\\\/\"},\"wordCount\":94,\"image\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/12\\\/02\\\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/LOAD-TEXT-FILE.png\",\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/12\\\/02\\\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\\\/\",\"url\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/12\\\/02\\\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\\\/\",\"name\":\"How To Load A Text File In Excel VBA With Load Data Infile - My Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/12\\\/02\\\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/12\\\/02\\\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/LOAD-TEXT-FILE.png\",\"datePublished\":\"2020-12-02T17:09:51+00:00\",\"dateModified\":\"2020-12-02T17:55:34+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/12\\\/02\\\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/12\\\/02\\\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/12\\\/02\\\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\\\/#primaryimage\",\"url\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/LOAD-TEXT-FILE.png\",\"contentUrl\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/LOAD-TEXT-FILE.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/12\\\/02\\\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Load A Text File In Excel VBA With Load Data Infile\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/\",\"name\":\"My Blog\",\"description\":\"My WordPress Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\\\/\\\/vbastring.com\\\/blog\"],\"url\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Load A Text File In Excel VBA With Load Data Infile - My Blog","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:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/","og_locale":"en_US","og_type":"article","og_title":"How To Load A Text File In Excel VBA With Load Data Infile - My Blog","og_description":"So for reference sake, here is something easy. This is how to load a local text file into a variable, so you can process it. For example: So you have some JSON file, and you put the JSON formatted text locally in a text file so you can experiment on parsing it before you actually [&hellip;]","og_url":"https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/","og_site_name":"My Blog","article_published_time":"2020-12-02T17:09:51+00:00","article_modified_time":"2020-12-02T17:55:34+00:00","og_image":[{"url":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2020\/12\/LOAD-TEXT-FILE.png","type":"","width":"","height":""}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/#article","isPartOf":{"@id":"https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/"},"author":{"name":"admin","@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5"},"headline":"How To Load A Text File In Excel VBA With Load Data Infile","datePublished":"2020-12-02T17:09:51+00:00","dateModified":"2020-12-02T17:55:34+00:00","mainEntityOfPage":{"@id":"https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/"},"wordCount":94,"image":{"@id":"https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/#primaryimage"},"thumbnailUrl":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2020\/12\/LOAD-TEXT-FILE.png","inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/","url":"https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/","name":"How To Load A Text File In Excel VBA With Load Data Infile - My Blog","isPartOf":{"@id":"https:\/\/vbastring.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/#primaryimage"},"image":{"@id":"https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/#primaryimage"},"thumbnailUrl":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2020\/12\/LOAD-TEXT-FILE.png","datePublished":"2020-12-02T17:09:51+00:00","dateModified":"2020-12-02T17:55:34+00:00","author":{"@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5"},"breadcrumb":{"@id":"https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/#primaryimage","url":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2020\/12\/LOAD-TEXT-FILE.png","contentUrl":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2020\/12\/LOAD-TEXT-FILE.png"},{"@type":"BreadcrumbList","@id":"https:\/\/vbastring.com\/blog\/2020\/12\/02\/how-to-load-a-text-file-in-excel-vba-with-load-data-infile\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vbastring.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How To Load A Text File In Excel VBA With Load Data Infile"}]},{"@type":"WebSite","@id":"https:\/\/vbastring.com\/blog\/#website","url":"https:\/\/vbastring.com\/blog\/","name":"My Blog","description":"My WordPress Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vbastring.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/vbastring.com\/blog"],"url":"https:\/\/vbastring.com\/blog\/author\/admin\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/comments?post=940"}],"version-history":[{"count":5,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/940\/revisions"}],"predecessor-version":[{"id":962,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/940\/revisions\/962"}],"wp:attachment":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/media?parent=940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/categories?post=940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/tags?post=940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}