Excel

Breaking news on Excel

Ease of Use

Easy

Version tested with

2002 

Submitted by:

ALe

Description:

Updated news from the site www.msnbc.msn.com will scroll on statusbar 

Discussion:

You can have breaking news without checking for it (so lazy!) and your boss think you're working so hard that you don't have time even for having a glance at news sites. Save and load the file as an add-in to have breaking news each time you work with Excel. 

Code:

instructions for use

			

'Thisworkbook Module Private Sub Workbook_BeforeClose(Cancel As Boolean) Call CancelAction End Sub Private Sub Workbook_Open() UpdateNews 'on opening update the query with the news from the site www.msnbc.msn.com Call ShowNews End Sub 'Module1 Public i As Integer 'integer to count news Public scadenza 'register time Public counter As Integer 'counter to set updating frequency Sub ShowNews() On Error GoTo fine 'if something doesn't work Dim MyNews As String 'string to store current news Dim AreaNews As Range 'range of news 'news stored in the queryof sheet News Set AreaNews = ThisWorkbook.Worksheets("News").Range(ThisWorkbook.Worksheets("News").Names("www.msnbc.msn")) 'first time macro is run or all news were shown so restart If i = 0 Or i = AreaNews.Cells.Count Then i = 1 If AreaNews.Cells(i).Value = vbNullString Then i = i + 1 'in case of blank cells MyNews = AreaNews.Cells(i).Value 'current news to be shown scadenza = Now + TimeSerial(0, 0, 5) 'calculate 5 seconds Application.OnTime scadenza, "GoNextNews" 'in 5 seconds run again Application.StatusBar = MyNews & " (CTRL+K to stop)" 'show in the statusbar Exit Sub fine: Call CancelAction End Sub Sub GoNextNews() i = i + 1 'skip to next news counter = counter + 1 'increment for frequency If counter = 100 Then Call UpdateNews 'change counter limit to change updating frequency Call ShowNews End Sub Sub UpdateNews() ThisWorkbook.Worksheets("News").QueryTables(1).Refresh 'update webquery End Sub 'Module2 Sub CancelAction() ' delete the scheduled launch of next news ' Quick launch: CTRL+k On Error Resume Next Application.OnTime earliesttime:=scadenza, Procedure:="GoNextNews", Schedule:=False 'clear Application.StatusBar = False scadenza = 0 i = 0 counter = 0 End Sub

How to use:

  1. Download the file and open it
  2. Or
  3. Open an Excel Workbook
  4. Press Alt + F11 to open the Visual Basic Editor (VBE)
  5. Select INSERT > MODULE from the menubar twice
  6. Paste code into the right pane
  7. Press Alt+Q to return to Excel
  8. Save workbook before any other changes
 

Test the code:

  1. Code will be executed at file opening
 

Sample File:

Breaking_news.zip 13.11KB 

Approved by mdmackillop


This entry has been viewed 635 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express