{"id":14557,"date":"2017-10-24T21:12:44","date_gmt":"2017-10-24T21:12:44","guid":{"rendered":"http:\/\/learnexcelmacro.com\/wp\/?p=14557"},"modified":"2017-10-25T08:11:48","modified_gmt":"2017-10-25T08:11:48","slug":"vba-to-open-a-password-protected-workbook","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/","title":{"rendered":"VBA to Open or Create a Password Protected Workbook"},"content":{"rendered":"

Dear Friends,<\/p>\n

Previously I have written about how to protect and un-protect a Sheet in a Workbook<\/strong><\/a>. In this article, I am going to cover all about protecting and unprotecting a workbook.<\/p>\n

This is going to be a short and simple article, yet informative and useful for your day to day VBA programming.<\/p>\n

In this article, I am going to share with you VBA code to:
\n1. Open a password protected Excel Workbook.
\n2. Create a password protected excel workbook.<\/p>\n

There is no special method for doing this. Rather it is simply done by passing the password parameters<\/em> in Workbooks.Open() <\/strong><\/a>and Workbook.SaveAs()<\/strong><\/a><\/p>\n

You can refer in the below code.<\/p>\n

How to create a password protected workbook<\/h1>\n

Let’s take an example where you want to save an Excel Workbook as password protected.<\/p>\n

\r\n\r\nFunction SaveWorkbookAsPasswordProtected\r\n    ActiveWorkbook.SaveAs Filename:=\"...\\protected.xlsx\", Password:=\"1234\", WriteResPassword:=\"1234\"\r\nEnd Function\r\n<\/code>\r\n<\/pre>\n

How to Open a password protected workbook<\/h1>\n

You can use following VBA code to open a password protected workbook to read or write.<\/p>\n

\r\n\r\nSub openPasswordProtectedWorkbook()\r\n    Workbooks.Open Filename:=\"...\\protected.xlsm\", Password:=\"1234\", WriteResPassword:=\"1234\"\r\nEnd Sub\r\n<\/code>\r\n<\/pre>\n
\n

Important:<\/h2>\n

Password: <\/strong> This is the password to lock the workbook from opening it.
\nWriteResPassword: <\/strong> This is the password to lock the workbook from EDITING it.<\/p>\n

If your workbook is locked with both the passwords – For opening and For editing<\/em><\/strong> – and you skip passing the password for editing, then you get a popup like below.
\nYou can ofcourse open that workbook in write mode by providing the correct password or in edit mode by clicking on the button shown on the popup.
\n

\"Protected<\/a>

Protected Workbook<\/p><\/div><\/p>\n<\/div>\n<\/span>","protected":false},"excerpt":{"rendered":"

Dear Friends, Previously I have written about how to protect and un-protect a Sheet in a Workbook. In this article, I am going to cover all about protecting and unprotecting a workbook. This is going to be a short and simple article, yet informative and useful for your day to day VBA programming. In this […]<\/p>\n","protected":false},"author":45,"featured_media":14568,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1246,1674],"tags":[],"class_list":["post-14557","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-macro","category-excel-macro-basics"],"yoast_head":"\nVBA to Open or Create a Password Protected Workbook - Let's excel in Excel<\/title>\n<meta name=\"description\" content=\"VBA to open a workbook which is password protected. VBA to Protect Workbook from Opening it. VBA to Protect Workbook from editing it. VBA to create Password protected workbook.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"VBA to Open or Create a Password Protected Workbook\" \/>\n<meta property=\"og:description\" content=\"VBA to open a workbook which is password protected. VBA to Protect Workbook from Opening it. VBA to Protect Workbook from editing it. VBA to create Password protected workbook.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/\" \/>\n<meta property=\"og:site_name\" content=\"Let's excel in Excel\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:author\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:published_time\" content=\"2017-10-24T21:12:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-10-25T08:11:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2017\/10\/Protect-Unprotct-Workbook.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"538\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Vishwamitra Mishra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/www.twitter.com\/learnexcelmacro\" \/>\n<meta name=\"twitter:site\" content=\"@learnexcelmacro\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vishwamitra Mishra\" \/>\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:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/\"},\"author\":{\"name\":\"Vishwamitra Mishra\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"headline\":\"VBA to Open or Create a Password Protected Workbook\",\"datePublished\":\"2017-10-24T21:12:44+00:00\",\"dateModified\":\"2017-10-25T08:11:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/\"},\"wordCount\":256,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"image\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2017\/10\/Protect-Unprotct-Workbook.jpg\",\"articleSection\":[\"Excel Macro\",\"Excel Macro Basics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/\",\"name\":\"VBA to Open or Create a Password Protected Workbook - Let's excel in Excel\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2017\/10\/Protect-Unprotct-Workbook.jpg\",\"datePublished\":\"2017-10-24T21:12:44+00:00\",\"dateModified\":\"2017-10-25T08:11:48+00:00\",\"description\":\"VBA to open a workbook which is password protected. VBA to Protect Workbook from Opening it. VBA to Protect Workbook from editing it. VBA to create Password protected workbook.\",\"breadcrumb\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#primaryimage\",\"url\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2017\/10\/Protect-Unprotct-Workbook.jpg\",\"contentUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2017\/10\/Protect-Unprotct-Workbook.jpg\",\"width\":800,\"height\":538,\"caption\":\"VBA to set password to Workbook\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/vmlogger.com\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel Macro\",\"item\":\"https:\/\/vmlogger.com\/excel\/macro\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"VBA to Open or Create a Password Protected Workbook\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\",\"url\":\"https:\/\/vmlogger.com\/excel\/\",\"name\":\"Let's excel in Excel\",\"description\":\"Let's share knowledge\",\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/vmlogger.com\/excel\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\",\"name\":\"Vishwamitra Mishra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"contentUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"width\":528,\"height\":560,\"caption\":\"Vishwamitra Mishra\"},\"logo\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\"},\"description\":\"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.\",\"sameAs\":[\"http:\/\/www.learnexcelmacro.com\",\"http:\/\/www.facebook.com\/vmlogger\",\"https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro\",\"https:\/\/www.youtube.com\/c\/VMLogger\"],\"url\":\"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"VBA to Open or Create a Password Protected Workbook - Let's excel in Excel","description":"VBA to open a workbook which is password protected. VBA to Protect Workbook from Opening it. VBA to Protect Workbook from editing it. VBA to create Password protected workbook.","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:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/","og_locale":"en_US","og_type":"article","og_title":"VBA to Open or Create a Password Protected Workbook","og_description":"VBA to open a workbook which is password protected. VBA to Protect Workbook from Opening it. VBA to Protect Workbook from editing it. VBA to create Password protected workbook.","og_url":"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/","og_site_name":"Let's excel in Excel","article_publisher":"http:\/\/www.facebook.com\/vmlogger","article_author":"http:\/\/www.facebook.com\/vmlogger","article_published_time":"2017-10-24T21:12:44+00:00","article_modified_time":"2017-10-25T08:11:48+00:00","og_image":[{"width":800,"height":538,"url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2017\/10\/Protect-Unprotct-Workbook.jpg","type":"image\/jpeg"}],"author":"Vishwamitra Mishra","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/www.twitter.com\/learnexcelmacro","twitter_site":"@learnexcelmacro","twitter_misc":{"Written by":"Vishwamitra Mishra","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#article","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/"},"author":{"name":"Vishwamitra Mishra","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"headline":"VBA to Open or Create a Password Protected Workbook","datePublished":"2017-10-24T21:12:44+00:00","dateModified":"2017-10-25T08:11:48+00:00","mainEntityOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/"},"wordCount":256,"commentCount":2,"publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"image":{"@id":"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#primaryimage"},"thumbnailUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2017\/10\/Protect-Unprotct-Workbook.jpg","articleSection":["Excel Macro","Excel Macro Basics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/","url":"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/","name":"VBA to Open or Create a Password Protected Workbook - Let's excel in Excel","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/#website"},"primaryImageOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#primaryimage"},"image":{"@id":"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#primaryimage"},"thumbnailUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2017\/10\/Protect-Unprotct-Workbook.jpg","datePublished":"2017-10-24T21:12:44+00:00","dateModified":"2017-10-25T08:11:48+00:00","description":"VBA to open a workbook which is password protected. VBA to Protect Workbook from Opening it. VBA to Protect Workbook from editing it. VBA to create Password protected workbook.","breadcrumb":{"@id":"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#primaryimage","url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2017\/10\/Protect-Unprotct-Workbook.jpg","contentUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2017\/10\/Protect-Unprotct-Workbook.jpg","width":800,"height":538,"caption":"VBA to set password to Workbook"},{"@type":"BreadcrumbList","@id":"https:\/\/vmlogger.com\/excel\/2017\/10\/vba-to-open-a-password-protected-workbook\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vmlogger.com\/excel\/"},{"@type":"ListItem","position":2,"name":"Excel Macro","item":"https:\/\/vmlogger.com\/excel\/macro\/"},{"@type":"ListItem","position":3,"name":"VBA to Open or Create a Password Protected Workbook"}]},{"@type":"WebSite","@id":"https:\/\/vmlogger.com\/excel\/#website","url":"https:\/\/vmlogger.com\/excel\/","name":"Let's excel in Excel","description":"Let's share knowledge","publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vmlogger.com\/excel\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5","name":"Vishwamitra Mishra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/","url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","contentUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","width":528,"height":560,"caption":"Vishwamitra Mishra"},"logo":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/"},"description":"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.","sameAs":["http:\/\/www.learnexcelmacro.com","http:\/\/www.facebook.com\/vmlogger","https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro","https:\/\/www.youtube.com\/c\/VMLogger"],"url":"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/"}]}},"_links":{"self":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/14557"}],"collection":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/users\/45"}],"replies":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/comments?post=14557"}],"version-history":[{"count":0,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/14557\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/media\/14568"}],"wp:attachment":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/media?parent=14557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/categories?post=14557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/tags?post=14557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}