{"id":12112,"date":"2011-12-29T20:19:45","date_gmt":"2011-12-29T20:19:45","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/?p=1121"},"modified":"2022-08-07T00:58:03","modified_gmt":"2022-08-07T00:58:03","slug":"strip-html-how-to-remove-html-tags-from-a-string-in-vba","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/","title":{"rendered":"Strip HTML : How to Remove HTML tags from a String in VBA"},"content":{"rendered":"

In this article I am going to write an User Defined Function (UDF) which is used to remove all HTMLs from a String Stored in Cell. It can be used as normal Inbuilt Formulas of Excel.<\/p>\n

For writing this function i have used VBScript Regular Expression to Replace all the HTML tags with BLANK “”. In code you can see i have defined a regular expression to replace all HTML tags.<\/p>\n

Regular Pattern which can be used to replace all HTML tags is : “<[^>]+>”<\/strong><\/p>\n

Follow the below Steps to create this UDF (User Defined Function):
\n1.<\/strong> Open Visual Basic Editor (Alt+ F11)
\n2.<\/strong> Open an Existing Module or add a New Module
\n3.<\/strong> Copy Paste the below Code and Save the Excel.
\n<\/p>\n

Function – Input as Cell Address<\/h3>\n
\r\nFunction StripHTML(cell As Range) As String\r\n Dim RegEx As Object\r\n Set RegEx = CreateObject(\"vbscript.regexp\")\r\n\r\n Dim sInput As String\r\n Dim sOut As String\r\n sInput = cell.Text\r\n \r\n With RegEx\r\n   .Global = True\r\n   .IgnoreCase = True\r\n   .MultiLine = True\r\n.Pattern = \"<[^>]+>\" 'Regular Expression for HTML Tags.\r\n End With\r\n\r\n sOut = RegEx.Replace(sInput, \"\")\r\n StripHTML = sOut\r\n Set RegEx = Nothing\r\nEnd Function\r\n<\/code><\/pre>\n

<\/p>\n

4.<\/strong> Now Go to any Cell of any Sheet of your Workbook and use this formula =stripHTML(Cell)<\/strong>
\n

\"REMOVE

REMOVE HTML TAGS FROM A STRING<\/p><\/div><\/p>\n

Function – Pass whole String with HTML<\/h3>\n

Below function can be basically used in VBA while writing some Macro.
\nFor example: At some point of time you recieve a string from some resource which has HTML tags with it and you want to remove all of them and want HTML tags free String then simply use this function.<\/p>\n

Syntax To Use this Function in your Macro:<\/strong><\/p>\n

\r\nhtmlFreeString=stripHTML(\"withHTMLString\")\r\n<\/code><\/pre>\n
\r\nFunction StripHTML(sInput As String) As String\r\n Dim RegEx As Object\r\n Set RegEx = CreateObject(\"vbscript.regexp\")\r\n\r\n Dim sOut As String\r\n With RegEx\r\n   .Global = True\r\n   .IgnoreCase = True\r\n   .MultiLine = True\r\n.Pattern = \"<[^>]+>\" 'Regular Expression for HTML Tags.\r\n End With\r\n\r\n sOut = RegEx.Replace(sInput, \"\")\r\n StripHTML = sOut\r\n Set RegEx = Nothing\r\nEnd Function\r\n<\/code><\/pre>\n<\/span>","protected":false},"excerpt":{"rendered":"

In this article I am going to write an User Defined Function (UDF) which is used to remove all HTMLs from a String Stored in Cell. It can be used as normal Inbuilt Formulas of Excel. For writing this function i have used VBScript Regular Expression to Replace all the HTML tags with BLANK “”. […]<\/p>\n","protected":false},"author":45,"featured_media":0,"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":[1673,1246,2056],"tags":[],"class_list":["post-12112","post","type-post","status-publish","format-standard","hentry","category-excel-functions","category-macro","category-udf"],"yoast_head":"\nStrip HTML : How to Remove HTML tags from a String in VBA - Let's excel in Excel<\/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:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Strip HTML : How to Remove HTML tags from a String in VBA\" \/>\n<meta property=\"og:description\" content=\"In this article I am going to write an User Defined Function (UDF) which is used to remove all HTMLs from a String Stored in Cell. It can be used as normal Inbuilt Formulas of Excel. For writing this function i have used VBScript Regular Expression to Replace all the HTML tags with BLANK “”. […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/\" \/>\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=\"2011-12-29T20:19:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-07T00:58:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2016\/12\/StripHTML.png\" \/>\n\t<meta property=\"og:image:width\" content=\"621\" \/>\n\t<meta property=\"og:image:height\" content=\"235\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/\"},\"author\":{\"name\":\"Vishwamitra Mishra\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"headline\":\"Strip HTML : How to Remove HTML tags from a String in VBA\",\"datePublished\":\"2011-12-29T20:19:45+00:00\",\"dateModified\":\"2022-08-07T00:58:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/\"},\"wordCount\":234,\"commentCount\":18,\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"image\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2016\/12\/StripHTML.png\",\"articleSection\":[\"Excel Functions\",\"Excel Macro\",\"User Defined Function\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/\",\"name\":\"Strip HTML : How to Remove HTML tags from a String in VBA - Let's excel in Excel\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2016\/12\/StripHTML.png\",\"datePublished\":\"2011-12-29T20:19:45+00:00\",\"dateModified\":\"2022-08-07T00:58:03+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#primaryimage\",\"url\":\"\",\"contentUrl\":\"\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/vmlogger.com\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel Functions\",\"item\":\"https:\/\/vmlogger.com\/excel\/excel-functions\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Strip HTML : How to Remove HTML tags from a String in VBA\"}]},{\"@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":"Strip HTML : How to Remove HTML tags from a String in VBA - Let's excel in Excel","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\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/","og_locale":"en_US","og_type":"article","og_title":"Strip HTML : How to Remove HTML tags from a String in VBA","og_description":"In this article I am going to write an User Defined Function (UDF) which is used to remove all HTMLs from a String Stored in Cell. It can be used as normal Inbuilt Formulas of Excel. For writing this function i have used VBScript Regular Expression to Replace all the HTML tags with BLANK “”. […]","og_url":"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/","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":"2011-12-29T20:19:45+00:00","article_modified_time":"2022-08-07T00:58:03+00:00","og_image":[{"width":621,"height":235,"url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2016\/12\/StripHTML.png","type":"image\/png"}],"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":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#article","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/"},"author":{"name":"Vishwamitra Mishra","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"headline":"Strip HTML : How to Remove HTML tags from a String in VBA","datePublished":"2011-12-29T20:19:45+00:00","dateModified":"2022-08-07T00:58:03+00:00","mainEntityOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/"},"wordCount":234,"commentCount":18,"publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"image":{"@id":"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#primaryimage"},"thumbnailUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2016\/12\/StripHTML.png","articleSection":["Excel Functions","Excel Macro","User Defined Function"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/","url":"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/","name":"Strip HTML : How to Remove HTML tags from a String in VBA - Let's excel in Excel","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/#website"},"primaryImageOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#primaryimage"},"image":{"@id":"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#primaryimage"},"thumbnailUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2016\/12\/StripHTML.png","datePublished":"2011-12-29T20:19:45+00:00","dateModified":"2022-08-07T00:58:03+00:00","breadcrumb":{"@id":"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/vmlogger.com\/excel\/2011\/12\/strip-html-how-to-remove-html-tags-from-a-string-in-vba\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vmlogger.com\/excel\/"},{"@type":"ListItem","position":2,"name":"Excel Functions","item":"https:\/\/vmlogger.com\/excel\/excel-functions\/"},{"@type":"ListItem","position":3,"name":"Strip HTML : How to Remove HTML tags from a String in VBA"}]},{"@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\/12112"}],"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=12112"}],"version-history":[{"count":0,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/12112\/revisions"}],"wp:attachment":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/media?parent=12112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/categories?post=12112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/tags?post=12112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}