{"id":741,"date":"2019-09-23T22:59:25","date_gmt":"2019-09-23T22:59:25","guid":{"rendered":"http:\/\/www.vbastring.com\/blog\/?p=741"},"modified":"2020-11-23T20:54:16","modified_gmt":"2020-11-23T20:54:16","slug":"shellexecute-vba-example-for-all-filetypes","status":"publish","type":"post","link":"https:\/\/vbastring.com\/blog\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/","title":{"rendered":"ShellExecute VBA Example (For All FileTypes)"},"content":{"rendered":"<p>This post is in response to an email question I received.<\/p>\n<p>Basically the person wanted to open an Excel file on their network using a command button in their application.<\/p>\n<p>From a button or a shape on your worksheet:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/09\/shellexecute1.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/09\/shellexecute1.png?resize=486%2C571\" alt=\"\" width=\"486\" height=\"571\" class=\"aligncenter size-full wp-image-744\" \/><\/a><\/p>\n<p>&#8230;assign the following macro (VBA) code:<\/p>\n<p>This code opens any type of file with the program specified to open the type of file:<\/p>\n<pre class=\"lang:vb decode:true \" >\r\n'this \"ShellExecute\" API Call needs to be in a module!\r\n\r\nPublic Declare Function ShellExecute Lib \"shell32.dll\" Alias \"ShellExecuteA\" _\r\n  (ByVal hWnd As Long, _\r\n   ByVal lpOperation As String, _\r\n   ByVal lpFile As String, _\r\n   ByVal lpParameters As String, _\r\n   ByVal lpDirectory As String, _\r\n   ByVal nShowCmd As Long) As Long\r\n\r\n\r\n'this is the regular procedure - you'll attach the \"OpenFile\" macro to your worksheet object, button, or shape\r\nSub OpenFile()\r\n    Dim RetVal As Long\r\n    \r\n    Dim strFileName As String\r\n    Dim strFolderPath As String\r\n    \r\n    strFolderPath = ThisWorkbook.Path &amp; \"\\\"\r\n    \r\n    strFileName = \"filetoopen.txt\"\r\n    \r\n    Call ShellExecute(0, \"Open\", strFolderPath &amp; strFileName &amp; vbNullString, vbNullString, vbNullString, 1)\r\n\r\n    \r\nEnd Sub<\/pre>\n<p>This opens txt, pdf, docx, xlsx, etc files.<\/p>\n<p>Let me know if you have any questions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post is in response to an email question I received. Basically the person wanted to open an Excel file on their network using a command button in their application. From a button or a shape on your worksheet: &#8230;assign the following macro (VBA) code: This code opens any type of file with the program [&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-741","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>ShellExecute VBA Example (For All FileTypes) - 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\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ShellExecute VBA Example (For All FileTypes) - My Blog\" \/>\n<meta property=\"og:description\" content=\"This post is in response to an email question I received. Basically the person wanted to open an Excel file on their network using a command button in their application. From a button or a shape on your worksheet: &#8230;assign the following macro (VBA) code: This code opens any type of file with the program [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vbastring.com\/blog\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/\" \/>\n<meta property=\"og:site_name\" content=\"My Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-09-23T22:59:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-11-23T20:54:16+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/09\/shellexecute1.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\\\/2019\\\/09\\\/23\\\/shellexecute-vba-example-for-all-filetypes\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/09\\\/23\\\/shellexecute-vba-example-for-all-filetypes\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\"},\"headline\":\"ShellExecute VBA Example (For All FileTypes)\",\"datePublished\":\"2019-09-23T22:59:25+00:00\",\"dateModified\":\"2020-11-23T20:54:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/09\\\/23\\\/shellexecute-vba-example-for-all-filetypes\\\/\"},\"wordCount\":84,\"image\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/09\\\/23\\\/shellexecute-vba-example-for-all-filetypes\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/shellexecute1.png\",\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/09\\\/23\\\/shellexecute-vba-example-for-all-filetypes\\\/\",\"url\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/09\\\/23\\\/shellexecute-vba-example-for-all-filetypes\\\/\",\"name\":\"ShellExecute VBA Example (For All FileTypes) - My Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/09\\\/23\\\/shellexecute-vba-example-for-all-filetypes\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/09\\\/23\\\/shellexecute-vba-example-for-all-filetypes\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/shellexecute1.png\",\"datePublished\":\"2019-09-23T22:59:25+00:00\",\"dateModified\":\"2020-11-23T20:54:16+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/09\\\/23\\\/shellexecute-vba-example-for-all-filetypes\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/09\\\/23\\\/shellexecute-vba-example-for-all-filetypes\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/09\\\/23\\\/shellexecute-vba-example-for-all-filetypes\\\/#primaryimage\",\"url\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/shellexecute1.png\",\"contentUrl\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/shellexecute1.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/09\\\/23\\\/shellexecute-vba-example-for-all-filetypes\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ShellExecute VBA Example (For All FileTypes)\"}]},{\"@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":"ShellExecute VBA Example (For All FileTypes) - 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\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/","og_locale":"en_US","og_type":"article","og_title":"ShellExecute VBA Example (For All FileTypes) - My Blog","og_description":"This post is in response to an email question I received. Basically the person wanted to open an Excel file on their network using a command button in their application. From a button or a shape on your worksheet: &#8230;assign the following macro (VBA) code: This code opens any type of file with the program [&hellip;]","og_url":"https:\/\/vbastring.com\/blog\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/","og_site_name":"My Blog","article_published_time":"2019-09-23T22:59:25+00:00","article_modified_time":"2020-11-23T20:54:16+00:00","og_image":[{"url":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/09\/shellexecute1.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\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/#article","isPartOf":{"@id":"https:\/\/vbastring.com\/blog\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/"},"author":{"name":"admin","@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5"},"headline":"ShellExecute VBA Example (For All FileTypes)","datePublished":"2019-09-23T22:59:25+00:00","dateModified":"2020-11-23T20:54:16+00:00","mainEntityOfPage":{"@id":"https:\/\/vbastring.com\/blog\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/"},"wordCount":84,"image":{"@id":"https:\/\/vbastring.com\/blog\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/#primaryimage"},"thumbnailUrl":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/09\/shellexecute1.png","inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/vbastring.com\/blog\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/","url":"https:\/\/vbastring.com\/blog\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/","name":"ShellExecute VBA Example (For All FileTypes) - My Blog","isPartOf":{"@id":"https:\/\/vbastring.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/vbastring.com\/blog\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/#primaryimage"},"image":{"@id":"https:\/\/vbastring.com\/blog\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/#primaryimage"},"thumbnailUrl":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/09\/shellexecute1.png","datePublished":"2019-09-23T22:59:25+00:00","dateModified":"2020-11-23T20:54:16+00:00","author":{"@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5"},"breadcrumb":{"@id":"https:\/\/vbastring.com\/blog\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vbastring.com\/blog\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vbastring.com\/blog\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/#primaryimage","url":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/09\/shellexecute1.png","contentUrl":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/09\/shellexecute1.png"},{"@type":"BreadcrumbList","@id":"https:\/\/vbastring.com\/blog\/2019\/09\/23\/shellexecute-vba-example-for-all-filetypes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vbastring.com\/blog\/"},{"@type":"ListItem","position":2,"name":"ShellExecute VBA Example (For All FileTypes)"}]},{"@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\/741","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=741"}],"version-history":[{"count":4,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/741\/revisions"}],"predecessor-version":[{"id":750,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/741\/revisions\/750"}],"wp:attachment":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/media?parent=741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/categories?post=741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/tags?post=741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}