Sub InsertAndFormatText()
Const wdColorBlue = 16711680
Dim olkTask As Outlook.TaskItem, _
objDoc As Object, _
objSel As Object, _
strTime As String, _
intStart As Integer, _
intLen As Integer
Set olkTask = Outlook.Application.ActiveInspector.CurrentItem
Set objDoc = olkTask.GetInspector.WordEditor
strTime = Format(Now, "ddd dd/m/yy h:mm AM/PM - ")
intLen = Len(strTime)
Set objSel = objDoc.Windows(1).Selection
intStart = objSel.Start
objSel.InsertAfter strTime
objDoc.Windows(1).Document.Range(intStart, intStart + intLen).Select
Set objSel = objDoc.Windows(1).Selection
With objSel
.Font.Bold = True
.Font.Color = wdColorBlue
End With
objDoc.Windows(1).Document.Range(intStart + intLen - 1, intStart + intLen + 1).Select
' Set objSel = objDoc.Windows(1).Selection
' With objSel
' .Font.Name = "Arial"
' .Font.Size = 12
' .Font.Bold = False
' .Font.Color = wdColorAutomatic
' End With
Set olkTask = Nothing
Set objDoc = Nothing
Set objSel = Nothing
End Sub
Open in New Window Select All
Sub InsertAndFormatText()
Const wdColorBlue = 16711680
Dim olkTask As Outlook.TaskItem, _
objDoc As Object, _
objSel As Object, _
strTime As String, _
intStart As Integer, _
intLen As Integer
Set olkTask = Outlook.Application.ActiveInspector.CurrentItem
Set objDoc = olkTask.GetInspector.WordEditor
strTime = Format(Now, "ddd dd/m/yy h:mm AM/PM - ")
intLen = Len(strTime)
Set objSel = objDoc.Windows(1).Selection
intStart = objSel.Start
objSel.InsertAfter strTime
Set objSel = objDoc.Windows(1).document.range
With objSel
.Font.Name = "Arial"
.Font.Size = 12
.Font.Bold = False
.Font.Color = wdColorAutomatic
End With
objDoc.Windows(1).Document.Range(intStart, intStart + intLen).Select
Set objSel = objDoc.Windows(1).Selection
With objSel
.Font.Bold = True
.Font.Color = wdColorBlue
End With
objDoc.Windows(1).Document.Range(intStart + intLen - 1, intStart + intLen + 1).Select
Set olkTask = Nothing
Set objDoc = Nothing
Set objSel = Nothing
End Sub
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.
Chris
Open in new window