{"id":12113,"date":"2012-01-03T10:52:11","date_gmt":"2012-01-03T10:52:11","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/?p=1136"},"modified":"2012-01-03T10:52:11","modified_gmt":"2012-01-03T10:52:11","slug":"how-to-login-to-gmail-from-excel-macro","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/","title":{"rendered":"How to interact with HTML pages from Excel"},"content":{"rendered":"

In this article you are going to learn how to interact with HTML pages from Excel Macro\/VBA. Though Excel is not much capable and easy enough to interact with HTML pages and its HTML controls. But up to some extend we can interact with HTML pages by Excel Macro.<\/p>\n

To interact with HTML pages and its controls we need to add two references in our Excel VBA.<\/p>\n

1. Microsoft HTML Object Library (mshtml.tlb): <\/strong> This library is required to access all HTML controls which can be present on your HTML page. <\/p>\n

2. Microsoft Internet Controls (ieframe.dll): <\/strong> This reference is required to do operations on Internet Explorer because to open an HTML page we need to access Internet Explorer.
\n<\/p>\n

How to Add Reference in Excel<\/h3>\n

1. Go to VB Editor Screen (Alt+F11)
\n 2. Tools \u2013> References\u2026
\n 3. From the List of Available References Select your Reference Name which you want to add.
\n Note:<\/strong> If you are not able to find the Reference Name in the list then Click on browse and select the dll name whihc is given for those Reference Names.
\n 4. Click OK
\n<\/p>\n

To explain how to open a browser and then a URL and after that recognize some controls on that page and pass some value in it and do some click operation etc, i have taken Gmail Login<\/strong> as an example. In the below example you will see how to login to Gmail from Excel Macro.<\/strong>
\n
\nNote:<\/strong> Read all the comments gievn in the code, which explains each statement will do what. See if this works for you. If you are facing any issue in this code, do let me know via comment or Mail Me<\/a><\/strong>
\n<\/p>\n

\nPrivate Sub CommandButton1_Click()\n\nDim HTMLDoc As HTMLDocument\nDim oBrowser As InternetExplorer\nDim oHTML_Element As IHTMLElement\n\n\nOn Error GoTo Err\n\nSet oBrowser = New InternetExplorer\noBrowser.Height = 1000\noBrowser.Width = 1000\noBrowser.Silent = False\n'oBrowser.tim\noBrowser.navigate \"http:\/\/gmail.com\"\noBrowser.Visible = False\n\nDo\n' Wait till the Browser is loaded\n\nLoop Until oBrowser.readyState = READYSTATE_COMPLETE\nSet HTMLDoc = oBrowser.Document\n\n'Once browser is fully loaded give few seconds\n'this is because sometimes even though the Browser State is\n'Complete but still some of the controls are not\n'ready completely. In such case your script may fail.\n'That's why i have given a waiting time of 3 seconds\n'after the page is loaded completely.\n\nApplication.Wait DateAdd(\"s\", 3, Now)\n\n'Once browser is open with Gmail URL\n'Now we need to pass ID and password at the right\n'field. For this right click on the Gmail page\n'and click on View Code. Here check the \"id\" of\n'User Name and Password Textboxes.\n'For example if ID of the User Name textbox is \"usrname\"\n'then syntax to pass User name in that field would be:\n'HTMLDoc.all.usrname.Value=\"your user name\".\n'Same way i have passed user name and password as below\n\nHTMLDoc.all.Email.Value = \"vishwamitra01\"\nHTMLDoc.all.Passwd.Value = \"*********\"\n\n'after entering email id and password\n'we need to search the button to Sign in gmail.\n'For this also we need to check the ID or name of that\n'button by right clicking and seeing the code.\n'Once you get the Name of that button then use the\n'below code to click on that.\n'Here for loop is necessary because if it is not able\n'to find the control in first time then it will go\n'and look for another button on that page.\n'Whichever button it is finiding with the name as\n'\"signIn\", it will click and for loop will end.\n\n\nFor Each oHTML_Element In HTMLDoc.getElementsByName(\"signIn\")\nIf oHTML_Element.Type = \"submit\" Then oHTML_Element.Click: Exit For\nNext\n\n\nDo\nLoop Until oBrowser.readyState = READYSTATE_COMPLETE\nApplication.Wait DateAdd(\"s\", 1, Now)\n\noBrowser.Visible = True\nExit Sub\nErr:\nMsgBox (\"Error Occured\")\n\nEnd Sub\n\n<\/code><\/pre>\n<\/span>","protected":false},"excerpt":{"rendered":"

In this article you are going to learn how to interact with HTML pages from Excel Macro\/VBA. Though Excel is not much capable and easy enough to interact with HTML pages and its HTML controls. But up to some extend we can interact with HTML pages by Excel Macro. To interact with HTML pages and […]<\/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":[1246],"tags":[],"yoast_head":"\nHow to interact with HTML pages from Excel - 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\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to interact with HTML pages from Excel\" \/>\n<meta property=\"og:description\" content=\"In this article you are going to learn how to interact with HTML pages from Excel Macro\/VBA. Though Excel is not much capable and easy enough to interact with HTML pages and its HTML controls. But up to some extend we can interact with HTML pages by Excel Macro. To interact with HTML pages and […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/\" \/>\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=\"2012-01-03T10:52:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/vmlogger.com_-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\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=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/\"},\"author\":{\"name\":\"Vishwamitra Mishra\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"headline\":\"How to interact with HTML pages from Excel\",\"datePublished\":\"2012-01-03T10:52:11+00:00\",\"dateModified\":\"2012-01-03T10:52:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/\"},\"wordCount\":283,\"commentCount\":30,\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"articleSection\":[\"Excel Macro\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/\",\"name\":\"How to interact with HTML pages from Excel - Let's excel in Excel\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\"},\"datePublished\":\"2012-01-03T10:52:11+00:00\",\"dateModified\":\"2012-01-03T10:52:11+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/#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\":\"How to interact with HTML pages from Excel\"}]},{\"@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\":\"required name=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:\/\/twitter.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":"How to interact with HTML pages from Excel - 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\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/","og_locale":"en_US","og_type":"article","og_title":"How to interact with HTML pages from Excel","og_description":"In this article you are going to learn how to interact with HTML pages from Excel Macro\/VBA. Though Excel is not much capable and easy enough to interact with HTML pages and its HTML controls. But up to some extend we can interact with HTML pages by Excel Macro. To interact with HTML pages and […]","og_url":"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/","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":"2012-01-03T10:52:11+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/vmlogger.com_-1.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":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/#article","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/"},"author":{"name":"Vishwamitra Mishra","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"headline":"How to interact with HTML pages from Excel","datePublished":"2012-01-03T10:52:11+00:00","dateModified":"2012-01-03T10:52:11+00:00","mainEntityOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/"},"wordCount":283,"commentCount":30,"publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"articleSection":["Excel Macro"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/","url":"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/","name":"How to interact with HTML pages from Excel - Let's excel in Excel","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/#website"},"datePublished":"2012-01-03T10:52:11+00:00","dateModified":"2012-01-03T10:52:11+00:00","breadcrumb":{"@id":"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/vmlogger.com\/excel\/2012\/01\/how-to-login-to-gmail-from-excel-macro\/#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":"How to interact with HTML pages from Excel"}]},{"@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":"required name=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:\/\/twitter.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\/12113"}],"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=12113"}],"version-history":[{"count":0,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/12113\/revisions"}],"wp:attachment":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/media?parent=12113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/categories?post=12113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/tags?post=12113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}