Converting Excel with Macros to Google Spreadsheets

Published in: Google Apps Script

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 = "" & symbol
    With Inet1
        .Open "GET", sStockPage, False
        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) = ">")

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

    Application.StatusBar = False

End Function
📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: Google Apps Script

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube