Open KML File Using VBA for Excel (Google API)
This article explains how you can use VBA for Excel to open a KML File.
Note: The google earth API will only be available if you have Google Earth installed on your computer.
The first step would be to add reference to the Google Earth 1.0 Type Library. Note the version might be different on your computer.
In the VBA editor create a new module and copy the code below inside it:
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
This line of code will allow us to use the Sleep function in our code.
The code below initiates google earth and opens the KML file located in path “D:StuffBusinessTemp”, under the name “Untitled Placemark.kml” :
Dim appGoogleEarth As EARTHLib.ApplicationGE
Set appGoogleEarth = New EARTHLib.ApplicationGE
Call appGoogleEarth.OpenKmlFile( _
"D:StuffBusinessTempUntitled Placemark.kml", 1)
Note: The reason for using the sleep function, is to allow Google Earth to load. If Google Earth has not finished loading and we attempt to open the KML file an error will occur.
You can download the file and code used in this article from the link below:
One thought on “Open KML File Using VBA for Excel (Google API)”