{"id":4845,"date":"2016-12-04T07:50:42","date_gmt":"2016-12-04T07:50:42","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/wp\/?p=4845"},"modified":"2017-07-18T12:48:57","modified_gmt":"2017-07-18T12:48:57","slug":"google-map-in-excel-using-vba","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2016\/12\/google-map-in-excel-using-vba\/","title":{"rendered":"VBA to Add Static Google Map in Excel Sheet"},"content":{"rendered":"
Dear Readers,<\/p>\n
In this article, I am going to give you a quick tip – how can you add google map in your excel workbook without opening the google map in any browser. More details about this will follow… Google map generator<\/p><\/div>\n Google Static Map API uses a URL which should be in this format: (copied from the above google documentation page)<\/p>\n https:\/\/maps.googleapis.com\/maps\/api\/staticmap?parameters<\/i><\/strong><\/p><\/blockquote>\n There are many possibilities of parameters which can be provided in order to generate your map.. again more details you can find it on above page<\/p>\n For example I am going to take a very basic map of any city of the world and show you how to use this API in excel.<\/p>\n I promise you, it is the simplest code you would ever see to use it in excel for such a cool thing.<\/p>\n Add a rectangle shape (ofcourse you can choose whatever shape you prefer) in your sheet any where you want to display the map and resize it according to your need.<\/p>\n Add a Shape for Map<\/p><\/div>\n Note:<\/strong>You can provide a name to that shape so that you can refer it in your by a relevant name. This is not a mandatory thing to do.<\/i><\/p>\n Follow below instruction to do so…<\/p>\n How to Name a Shape in Excel<\/p><\/div>\n Form your URL based on different parameters you would like. For example to generate the Map of Amsterdam City in 400X400 size with Zoom Level: 14, following would be the URL.<\/p>\n [one_full spacing=”yes” last=”no” center_content=”no” hide_on_mobile=”no” background_color=”#FEF6D2″ background_image=”” background_repeat=”no-repeat” background_position=”left top” link=”” hover_type=”none” border_position=”all” border_size=”1.5px” border_color=”#EDDB93″ border_style=”solid” padding=”10px” margin_top=”” margin_bottom=”” animation_type=”0″ animation_direction=”down” animation_speed=”0.1″ animation_offset=”” class=”” id=””]https:\/\/maps.googleapis.com\/maps\/api\/staticmap?center=Amsterdam&zoom=14&size=400\u00d7400[\/one_full]<\/p>\n Note: To check whether your URL is correct or not, you can simply open this URL as it is in any browser. If you see a static map images generated, that means your URL is correct and you can go ahead and use it in your Excel VBA code.<\/p>\n VBA code to execute to display the City map of Amsterdam in the rectangle shape<\/p>\n Now you know how to include a map in your excel sheet using excel vba and Google Static Map API?<\/p>\n Based on the above explanation, I have created a sample workbook, which you can download and play around with it.<\/p><\/blockquote>\n Download this, use it and do not forget to provide me your feedback by typing your comment here or sending en email or you can tweet me <\/a> You can also share it with your friends, colleagues or whomsoever you want to!!<\/p>\n\n<\/span>","protected":false},"excerpt":{"rendered":" Dear Readers, In this article, I am going to give you a quick tip – how can you add google map in your excel workbook without opening the google map in any browser. More details about this will follow… To do that I am using Google Static Map API. I am not going explain you […]<\/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,1675],"tags":[],"class_list":["post-4845","post","type-post","status-publish","format-standard","hentry","category-macro","category-excel-macro-for-beginners"],"yoast_head":"\n
\nTo do that I am using Google Static Map API<\/strong><\/a>. I am not going explain you more about this API here as you can already get whole lot of information about this API here on this page… Click here…<\/strong><\/a> At the end of this article you will find a downloadable workbook like below. Where you will be able to generate different Cities map or different type.<\/p>\nParameters<\/h2>\n
Step 1. A Placeholder to keep your generated Map<\/h1>\n
<\/a>
How to provide a name to the Shape in Excel – you added above?<\/h1>\n
<\/a>
Step 2. Generate URL for Google Static Map API<\/h1>\n
Step 3. VBA Code to display Google Static Map<\/h1>\n
\r\nSub insertMap()\r\n ' prepare your google static map API\r\n gAPIMapUrl = "https:\/\/maps.googleapis.com\/maps\/api\/staticmap?center=Amsterdam&zoom=12&size=640x640"\r\n Shapes("your Shape Name").Fill.UserPicture gAPIMapUrl\r\nEnd Sub\r\n<\/code><\/pre>\n
Download Sample MAP Generator Excel<\/h1>\n