For my reference and others.
I wrote some VBA code to search for keywords in task notes.
By creating a tool bar button it becomes very useful.
I've also written a subroutine to export all notes in the current view
to excel.
Regards
Rudiger Wolf
Public Const xlHAlignCenter = -4108
Public Const xlHAlignCenterAcrossSelection = 7
Public Const xlHAlignDistributed = -4117
Public Const xlHAlignFill = 5
Public Const xlHAlignGeneral = 1
Public Const xlHAlignJustify = -4130
Public Const xlHAlignLeft = -4131
Public Const xlHAlignRight = -4152
Public Const xlVAlignBottom = -4107
Public Const xlVAlignCenter = -4108
Public Const xlVAlignDistributed = -4117
Public Const xlVAlignJustify = -4130
Public Const xlVAlignTop = -4160
Public Sub SearchNotes()
'------------------------------------------------------------------------
' This function can be used to search for a keyword in the task notes.
' The task list is filtered to display only those that contain the
keyword.
' So one can keep on filtering until you have the desired task and note
' 16 April 2006
'------------------------------------------------------------------------
Dim aTask As Task
Dim MsgBoxReturn As Integer
Dim foundCount As Integer
Dim SearchString As String
Dim longnumber As Long
Dim noteText As String 'The task notes variable
foundCount = 0
SearchString = LCase(InputBox("Enter lowercase keyword to search for"))
SelectAll
For Each aTask In ActiveSelection.Tasks
aTask.Flag15 = False
If Len(aTask.Notes) > 0 Then
noteText = ""
noteText = LCase(aTask.Notes)
If InStr(noteText, SearchString) > 0 Then
'Debug.Print "Found """ & SearchString & """ in task
UniqueID=", aTask.UniqueID
aTask.Flag15 = True
foundCount = foundCount + 1
End If
End If
Next
If foundCount > 0 Then
'Apply a filter for those rows that have Flag15 = True
FilterEdit Name:="FliterSearchNotes", TaskFilter:=True,
Create:=True, OverwriteExisting:=True, FieldName:="Flag15",
Test:="equals", Value:="Yes", ShowInMenu:=False,
ShowSummaryTasks:=False
FilterApply Name:="FliterSearchNotes"
MsgBoxReturn = MsgBox("Keyword found in " & foundCount & " tasks",
vbOKOnly)
Else
MsgBoxReturn = MsgBox("Keyword """ & SearchString & """ not found
any task notes", vbOKOnly)
End If
End Sub
Sub ExportNotesToexcel()
'---------------------------------------------------------------
' This subroutine takes all the task notes in the current view
' opens up excel and exports notes and related info to excel.
' 16 April 2006
'---------------------------------------------------------------
'Open Excel for data dump
Dim s As Object
Dim c As Object
Dim Xl As Object
Dim xlRng As Object
Dim Proj As Project
Dim aTask As Task
Dim aAss As Assignment
Dim AssNames As String
On Error Resume Next
'Check for existing instance of Excel; if not running, start Excel
Set Xl = GetObject(, "Excel.application")
If Err <> 0 Then
On Error GoTo 0 'clear error function
Set Xl = CreateObject("Excel.Application")
If Err <> 0 Then
MsgBox "Excel application is not available on this workstation"
_
& Chr(13) & "Install Excel or check network connection",
vbCritical, "Fatal Error"
Exit Sub
End If
End If
'Clear error trap and add a new workbook for each successive run
On Error GoTo 0
Xl.Workbooks.Add
Set xlRng = Xl.ActiveCell
'Keep Excel in the background until spreadsheet is done (speeds
transfer)
Xl.Visible = False
Xl.ScreenUpdating = False
Xl.DisplayAlerts = False
'Write and format title
Set Proj = ActiveProject 'Using Proj is slightly faster
xlRng = "Task Notes Export Report for " & Proj.Name
xlRng.Range("A2") = "As of " & Format(Date, "mmmm d yyyy")
xlRng.Range("A1:A2").Font.Bold = True
xlRng.Font.Size = 12
'Move xlRng below titles
Set xlRng = xlRng.Offset(3, 0)
'Create column titles and format
xlRng.Offset(0, 1) = "UniqueID"
xlRng.Offset(0, 2) = "ID"
xlRng.Offset(0, 3) = "Task Name"
xlRng.Offset(0, 4) = "Start"
xlRng.Offset(0, 5) = "Note"
xlRng.Offset(0, 6) = "Assigned Resources"
'Make excel visible for debuging
'Xl.DisplayAlerts = False
'Xl.ScreenUpdating = True
'Xl.Visible = True
Set xlRng = xlRng.Offset(1, 0) 'Down 1 rows
SelectAll
For Each aTask In ActiveSelection.Tasks
If Len(aTask.Notes) > 0 Then
xlRng.Offset(0, 1) = aTask.UniqueID
xlRng.Offset(0, 2) = aTask.ID
xlRng.Offset(0, 3) = aTask.Name
xlRng.Offset(0, 4) = aTask.Start
xlRng.Offset(0, 4).NumberFormat = "dd mmm yy;@"
xlRng.Offset(0, 5) = Replace(aTask.Notes, vbCr, vbLf) ' Get
rid of the little squares!
AssNames = ""
For Each aAss In aTask.Assignments
AssNames = AssNames & aAss.ResourceName & vbLf
Next aAss
xlRng.Offset(0, 6) = AssNames
With xlRng.EntireRow
.WrapText = True
.RowHeight = 50
.HorizontalAlignment = xlHAlignCenter
.VerticalAlignment = xlVAlignTop
End With
Set xlRng = xlRng.Offset(1, 0) 'Down 1 rows
End If
Next
'Make excel visible
Xl.ScreenUpdating = True
Xl.DisplayAlerts = True
Xl.Visible = True
End Sub