Converting Excel with Macros to Google Spreadsheets

One of my recent project involved converting a finance related Microsoft Excel Spreadsheet into a web based Google Spreadsheet that can be accessed from a web browser. The Excel sheet had VBA Macros that were converted into corresponding functions using Google Apps Scripts.

Here’s one such VBA routine that scraped Yahoo Finance and was rewritten in Google Apps. In Visual Basic, you create an XMLHttpRequest object to connect to an external server which can be replaced with URLFetch in Apps Script. The debug.print methods can be replaced with Logger.log while the regular JavaScript functions can be used for text manipulation.

The StatusBar property of the Application object in Excel VBA displays the macro progress in the Excel UI and you can replace it with the .toast() method of SpreadsheetApp class in Google Scripts.

Function GetFundName(symbol As String) As String

    Dim Inet1 'As Inet
    Dim fndSym As Integer, endCnt As Integer, begCnt As Integer
    Dim bFound As Boolean

    Application.StatusBar = "Getting Fund Name for " & symbol

    Set Inet1 = CreateObject("Microsoft.XMLHTTP")
    sStockPage = "http://finance.yahoo.com/q/hp?s=" & symbol
    With Inet1
        .Open "GET", sStockPage, False
        .send
        sStockPage = Inet1.ResponseText
    End With
    Set Inet1 = Nothing

    fndSym = InStrRev(sStockPage, "(" & symbol) // .indexOf in JS
    endCnt = fndSym - 2
    bFound = False
    Do Until bFound
        fndSym = fndSym - 1
        'Debug.Print (Mid(sStockPage, fndSym, 1)) // Logger.log in Google Scripts
        bFound = (Mid(sStockPage, fndSym, 1) = ">")
    Loop

    GetFundName = Mid(sStockPage, fndSym + 1, endCnt - fndSym + 1) // .substring() in JS

    Application.StatusBar = False

End Function

Amit Agarwal is a web geek, solo entrepreneur and loves making things on the Internet. Google recently awarded him the Google Developer Expert and Google Cloud Champion title for his work on Google Workspace and Google Apps Script.

Awards & Recognition

Google Developer Expert

Google Developer Expert

Google awarded us the Developer Expert title recogizing our work in Workspace

ProductHunt Golden Kitty

ProductHunt Golden Kitty

Our Gmail tool won the Lifehack of the Year award at ProductHunt Golden Kitty Awards

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional title for 5 years in a row

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator award for technical expertise

Want to stay up to date?
Sign up for our email newsletter.

We will never send any spam emails. Promise 🫶🏻