{"id":716,"date":"2013-02-21T21:40:41","date_gmt":"2013-02-21T21:40:41","guid":{"rendered":"http:\/\/www.microsofttraining.net\/b\/vbatraining\/?p=14"},"modified":"2023-12-30T23:28:45","modified_gmt":"2023-12-30T23:28:45","slug":"using-vba-to-call-the-windows-file-open-dialog-box","status":"publish","type":"post","link":"https:\/\/www.stl-training.co.uk\/b\/using-vba-to-call-the-windows-file-open-dialog-box\/","title":{"rendered":"Using VBA to call the Windows File Open dialog box"},"content":{"rendered":"<p>After you&#8217;ve worked with VBA for a while, you&#8217;re going to want to <strong>prompt the user to open a file<\/strong>. Maybe they need to go and select the latest download from their database, or you need to import the contents of the latest sales data. Whatever the scenario, you&#8217;re going to need to access the <strong>Windows file dialogue<\/strong>.<\/p>\n<p>Over on the forum part of our site, we&#8217;ve detailed a method you can use regarding the\u00a0<a title=\"Microsoft Office Training VBA forum\" href=\"https:\/\/www.stl-training.co.uk\/post-26114-open-windows-file-dialog.html\" target=\"_blank\" rel=\"noopener\">msoFileDialogFilePicker method<\/a>. It involved creating a custom user form and reading in the selected filename.<\/p>\n<p>Here&#8217;s an alternative: use the built-in system dialogue box.<\/p>\n<pre>workbooks.Open(Application.GetOpenFilename())<\/pre>\n<figure id=\"attachment_1920\" aria-describedby=\"caption-attachment-1920\" style=\"width: 737px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2013\/02\/file-open-dialogue.png\"><img decoding=\"async\" class=\"size-full wp-image-1920\" src=\"https:\/\/www.stl-training.co.uk\/b\/wp-content\/uploads\/2013\/02\/file-open-dialogue.png\" alt=\"open file dialogue triggered from excel vba\" width=\"737\" height=\"549\" \/><\/a><figcaption id=\"caption-attachment-1920\" class=\"wp-caption-text\">The Open File dialogue.<\/figcaption><\/figure>\n<p>The Workbooks.Open() command is straightforward: in the brackets you can input a filename. It&#8217;s common to put a variable in there. In this case, we&#8217;re using the Application.GetOpenFilename() command which executes the standard File Open dialogue box for Excel. The workbook selected will be opened.<\/p>\n<p>There&#8217;s also a number of arguments for the GetOpenFilename property, filtering by types, allowing multiple files to be selected&#8230; here&#8217;s a <a title=\"microsoft vba getopenfilename\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/office\/ff834966.aspx\" target=\"_blank\" rel=\"noopener\">full description of the GetOpenFilename arguments<\/a>.<\/p>\n<p><em>Want to find out more VBA tricks and tips? Attend a <a title=\"excel vba training courses london and uk wide\" href=\"https:\/\/www.stl-training.co.uk\/excel-vba-2010-training-course.php\" target=\"_blank\" rel=\"noopener\">Best STL\u00a0VBA training course<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>After you&#8217;ve worked with VBA for a while, you&#8217;re going to want to prompt the user to open a file. Maybe they need to go and select the latest download from their database, or you need to import the contents of the latest sales data. Whatever the scenario, you&#8217;re going to need to access the [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[19],"tags":[97,571,582,611],"class_list":["post-716","post","type-post","status-publish","format-standard","hentry","category-vba-training","tag-code-sample","tag-vba","tag-visual-basic","tag-working-with-files"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/posts\/716","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/comments?post=716"}],"version-history":[{"count":1,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/posts\/716\/revisions"}],"predecessor-version":[{"id":6873,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/posts\/716\/revisions\/6873"}],"wp:attachment":[{"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/media?parent=716"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/categories?post=716"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stl-training.co.uk\/b\/wp-json\/wp\/v2\/tags?post=716"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}