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 more about this API here as you can already get whole lot of information about this API here on this page… Click here… 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.
Google Static Map API uses a URL which should be in this format: (copied from the above google documentation page)
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
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.
I promise you, it is the simplest code you would ever see to use it in excel for such a cool thing.
Step 1. A Placeholder to keep your generated Map
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.
Note: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.
How to provide a name to the Shape in Excel – you added above?
Follow below instruction to do so…
Step 2. Generate URL for Google Static Map API
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.
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.
Step 3. VBA Code to display Google Static Map
VBA code to execute to display the City map of Amsterdam in the rectangle shape
Sub insertMap() ' prepare your google static map API gAPIMapUrl = "https://maps.googleapis.com/maps/api/staticmap?center=Amsterdam&zoom=12&size=640x640" Shapes("your Shape Name").Fill.UserPicture gAPIMapUrl End Sub
Now you know how to include a map in your excel sheet using excel vba and Google Static Map API?
Based on the above explanation, I have created a sample workbook, which you can download and play around with it.
Download Sample MAP Generator Excel
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 You can also share it with your friends, colleagues or whomsoever you want to!!