VBOffice

Add date at the cursor position

This macro is useful if you want to add a new note, for instance, to a contact or task.

Last modified: 2019/06/13 | Accessed: 22.418  | #170
◀ Previous sample Next sample ▶

Content

ReplyAll ReplyAll
ReplyAll alerts you before unintentionally replying all, or if you are a confidential BCC recipient of the e-mail.

Insert date at the top of the body

This sample inserts the date at the top of the body. See the DefaultMsg variable in the AddNote method, here you can set a default message that should be added together with the date.

In order to use this sample you need to add a reference to the 'Microsoft Word x.x Object Library' via Tools/References.


tip  How to add macros to Outlook
Public Sub AddNote()
  Dim DefaultMsg$
  
  DefaultMsg = ""
  
  AddNote_Ex Application.ActiveInspector, DefaultMsg
End Sub

Private Sub AddNote_Ex(Inspector As Outlook.Inspector, Optional Msg As String)
  Dim WdSel As Word.Selection
  Dim p&

  Msg = Format(Date, "mm/dd/yyyy", vbUseSystemDayOfWeek, vbUseSystem) & _
    ": " & Msg
  Msg = vbCrLf & "---" & vbCrLf & Msg
  Set WdSel = GetCurrentWordSelection(Inspector)
  p = Len(Msg) - 2
  WdSel.Start = 0
  WdSel.End = 0
  WdSel.InsertBefore Msg
  WdSel.Start = WdSel.Start + p
  WdSel.End = WdSel.Start
End Sub

Private Function GetCurrentWordSelection(OpenInspector As Outlook.Inspector) As Word.Selection
  Dim Doc As Word.Document
  Dim Wd As Word.Application
  
  Set Doc = OpenInspector.WordEditor
  Set Wd = Doc.Application
  Set GetCurrentWordSelection = Wd.Selection
End Function
Category-Manager Category-Manager
With Category-Manager you can group your Outlook categories, share them with other users, filter a folder by category, automatically categorize new emails, and more. You can use the Addin even for IMAP.

Insert date at the current cursor position

This sample is similar to the first one, but this time the date is inserted at the current position of the cursor within the body. (Inserting anything in another text field than the body doesn´t work this way.)

In order to use this sample you need to add a reference to the 'Microsoft Word x.x Object Library' via Tools/References.

Public Sub AddNote()
  Dim DefaultMsg$
  
  DefaultMsg = ""
  
  AddNote_Ex Application.ActiveInspector, DefaultMsg
End Sub

Private Sub AddNote_Ex(Inspector As Outlook.Inspector, Optional Msg As String)
  Dim WdSel As Word.Selection
  Dim p&

  Msg = Format(Date, "mm/dd/yyyy", vbUseSystemDayOfWeek, vbUseSystem) & _
    ": " & Msg
  Msg = vbCrLf & "---" & vbCrLf & Msg
  Set WdSel = GetCurrentWordSelection(Inspector)
  p = Len(Msg) - 2
  WdSel.End = WdSel.Start
  WdSel.InsertBefore Msg
  WdSel.Start = WdSel.Start + p
  WdSel.End = WdSel.Start
End Sub

Private Function GetCurrentWordSelection(OpenInspector As Outlook.Inspector) As Word.Selection
  Dim Doc As Word.Document
  Dim Wd As Word.Application
  
  Set Doc = OpenInspector.WordEditor
  Set Wd = Doc.Application
  Set GetCurrentWordSelection = Wd.Selection
End Function
ReplyAll ReplyAll
ReplyAll alerts you before unintentionally replying all, or if you are a confidential BCC recipient of the e-mail.
email  Send a message