Code below submitted by user Kyle123, makes for a seamless word cloud integration within excel. I am hoping to make a few tweaks. Specifically I'd like to find a way to change the colors of my 5 top occurring words (i.e. make the biggest boldest tags appear red as they represent a high occurrence of injuries for my specific use. I'd also like to be able to run off of whatever portion of a column I currently have selected, rather than statically referencing say A1:A50.
The second goal should be easy within the vba, but I'm guessing the first change would have to reside within http://visapi-gadgets.googlecode.com...rdcloud/wc.css, http://visapi-gadgets.googlecode.com...ordcloud/wc.js, or text/javascript"" src=""http://www.google.com/jsapi""></script>. My apologies, I'm not very familiar with google visualizations or jquery. And thank you Kyle123 for what seems to be one of the best inclusions of a word cloud generating tool within excel.
Sub test()
Dim CloudData As Range
'WordCloud Sheet1.Range("A1:A50")
Selection.Name = "CloudData"
WordCloud Sheet1.Range("CloudData")
End Sub
Sub WordCloud(rngInput As Range)
Dim wbString As String
Dim myFile As String
Dim rngVar As Variant
Dim fnum As Integer
Dim i As Integer
rngVar = Application.Transpose(rngInput.Value)
wbString = "<html>" & vbCr
wbString = wbString & " <head>"
wbString = wbString & " <link rel=""stylesheet"" type=""text/css"" href=""http://visapi-gadgets.googlecode.com/svn/trunk/wordcloud/wc.css""></script>" & vbCr
wbString = wbString & " <script type=""text/javascript"" src=""http://visapi-gadgets.googlecode.com/svn/trunk/wordcloud/wc.js""></script>" & vbCr
wbString = wbString & " <script type=""text/javascript"" src=""http://www.google.com/jsapi""></script>" & vbCr
wbString = wbString & " </head>" & vbCr
wbString = wbString & " <body>" & vbCr
wbString = wbString & " <div id=""wcdiv""></div>" & vbCr
wbString = wbString & " <script type=""text/javascript"">" & vbCr
wbString = wbString & " google.load('visualization', '1');" & vbCr
wbString = wbString & " google.setOnLoadCallback(draw);" & vbCr
wbString = wbString & " function draw() {" & vbCr
wbString = wbString & " var data = new google.visualization.DataTable();" & vbCr
wbString = wbString & " data.addColumn('string', 'Text1');" & vbCr
wbString = wbString & " data.addRows(" & UBound(rngVar) & ");" & vbCr
For i = 1 To UBound(rngVar)
wbString = wbString & " data.setCell(" & i - 1 & ", 0,'" & rngVar(i) & "');" & vbCr
Next i
wbString = wbString & " var outputDiv = document.getElementById('wcdiv');" & vbCr
wbString = wbString & " var wc = new WordCloud(outputDiv);" & vbCr
wbString = wbString & " wc.draw(data, null);" & vbCr
wbString = wbString & " }" & vbCr
wbString = wbString & " </script>" & vbCr
wbString = wbString & " </body>" & vbCr
wbString = wbString & "</html>"
myFile = ThisWorkbook.Path & "\WordCloud.htm"
fnum = FreeFile()
Open myFile For Output As fnum
Print #fnum, wbString
Close #fnum
With Cloud.WebBrowser1
.Silent = True
.Navigate (myFile)
Do
DoEvents
Loop Until .ReadyState = READYSTATE_COMPLETE
.Document.body.Scroll = "no"
End With
End Sub
Bookmarks