Create tag Clouds from twitter in Excel

The tagCloud class
Today’s post will demonstrate how to generate tagClouds from various sources in Excel. As an example we will use some tweets retrieved by the rest- Excel library

A ‘Mitt Romney’ type query generates this tagCloud

 

The VBA code to create this uses classes from the ramblings sitecTagCloud ,  cDataSet. and heatMap.

 

Public Sub testTag()
    Dim ds As New cDataSet, dr As cDataRow, tg As New cTagCloud
  
    tg.init , , 3, " "
    With ds.populateData(wholeSheet("tweetsentimentdetails"), , , , , , True)
        For Each dr In .Rows
            tg.collect dr.Cell("text").toString
        Next dr
    End With
    tg.results Sheets("tagout").Range("a1")
End Sub

A single Cell
The example above reports on a  complete worksheet column. Here’s how to do a single cell, and is in the spirit of many posts  such as rest-excel-json-excel in one line of code

Newt Gingrich’s wikipedia entry gives this

 

with this one liner.

Public Sub testTagSingleCell()
    Dim tg As New cTagCloud
    tg.init(, , 5, " ").collect( _
        Sheets("singleTag").Range("a1").Value _
        ).results Sheets("singleTag").Range("b1")
End Sub

Multiple tags
Finally, here’s how to consolidate multiple tags from multiple workbooks, this time comparing Obama and Romney sentiment on tax and charity.

 

and here is the code,

Public Sub testWorkbookTag()
    Dim ds As cDataSet, dr As cDataRow, tg As cTagCloud, drin As cDataRow
    Dim din As cDataSet
  
    Set din = New cDataSet
    din.populateData wholeSheet("tagBook"), , , , , , True
  
    For Each drin In din.Rows
        Set tg = New cTagCloud
        tg.init , , 3, " "
        Set ds = New cDataSet
        With ds.populateData(wholeSheet(drin.Cell("sheet").toString), _
                               , , , , , True)
            For Each dr In .Rows
                tg.collect dr.Cell("text").toString
            Next dr
            tg.results drin.Cell("tags").where
        End With
    Next drin

End Sub

You can read more about this and download these and other examples at the ramblings site. Although the examples here are based on tweet data, you can of course use any Excel data.

About brucemcp 225 Articles
I am a Google Developer Expert and decided to investigate Google Apps Script in my spare time. The more I investigated the more content I created so this site is extremely rich. Now, in 2019, a lot of things have disappeared or don’t work anymore due to Google having retired some stuff. I am however leaving things as is and where I came across some deprecated stuff, I have indicated it. I decided to write a book about it and to also create videos to teach developers who want to learn Google Apps Script. If you find the material contained in this site useful, you can support me by buying my books and or videos.