VBA to Add Static Google Map in Excel Sheet

.

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 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 map generator

Google map generator

Google Static Map API uses a URL which should be in this format: (copied from the above google documentation page)

https://maps.googleapis.com/maps/api/staticmap?parameters

Parameters

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.

Add a Shape for Map

Add a Shape for Map

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…

How to Name a Shape in Excel

How to Name a Shape in Excel

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.

[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×400[/one_full]

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!!

Buy a coffee for the author

Adsense

Download FREE Tools and Templates

There are many cool and useful excel tools and templates available to download for free. For most of the tools, you get the entire VBA code base too which you can look into it, play around it, and customize according to your need.

Dynamic Arrays and Spill Functions in Excel: A Beginner’s Guide
Dynamic Arrays and Spill Functions in Excel: A Beginner’s Guide

In today's tutorial, we'll be diving into the exciting world of dynamic arrays and spill functions in Office 365 Excel. These features have revolutionized the way we work with data, providing a more flexible and efficient way to handle arrays. I am going to explain...

How to Declare a Public Variable in VBA
How to Declare a Public Variable in VBA

While programming in VBA sometimes you need to declare a Public Variable that can store the value throughout the program. Use of Public Variable: Let's say you have 4 different Functions in your VBA Code or Module and you have a variable that may or may not be...

How to Copy content from Word using VBA

As many of us want to deal with Microsoft Word Document from Excel Macro/VBA. I am going to write few articles about Word from Excel Macro. This is the first article which opens a Word Document and read the whole content of that Word Document and put it in the Active...

What is Excel Formula?

Excel Formula is one of the best feature in Microsoft Excel, which makes Excel a very very rich application. There are so many useful built-in formulas available in Excel, which makes our work easier in Excel. For all the automated work, Excel Macro is not required. There are so many automated things can be done by using simple formulas in Excel. Formulas are simple text (With a Syntax) which is entered in to the Excel Worksheet Cells. So how computer will recognize whether it is a formula or simple text? Answer is simple.. every formula in Excel starts with Equal Sign (=).

You May Also Like…

1 Comment

  1. Yanli

    Does this tutorial still work? Is a API key needed for this work?

    Reply

Trackbacks/Pingbacks

  1. Welcome to LearnExcelMacro.com Excel VBA : Distance and duration between two places - […] week, As I had placed an article on how to create static google map in excel using Google Static…
  2. Excel VBA : Distance and duration between two places - […] week, As I had placed an article on how to create static google map in excel using Google Static…
  3. Distance Calculator in Excel VBA [REVISED] - Welcome to LearnExcelMacro.com - […] guys, on June 2016, google made some changes around pricing and authentication etc. of its FREE APIs. Distance calculator…
  4. Distance Calculator in Excel VBA [REVISED] - Let's excel in Excel - […] distance between two places in Excel [With Fun] VBA to Add Static Google Map in Excel Sheet Invoice Template…

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Join and get a FREE! e-Book

Don't miss any articles, tools, tips and tricks, I publish here

You have Successfully Subscribed!

Pin It on Pinterest