Pls help to change the code for inserting date in Ol contact body

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Hi

Here is the code
it puts a date AT THE TOP of The OL contact body
Pls help to put the date AT THE END of the contact body

Code:
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

What to change
THX
regards
Witzker
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
WdSel.InsertBefore Msg inserts it before the current line. insertafter will insert it after the first line. IOf you want it at the end of everything, you need to move the cursory to the end -
WdSel.EndKey Unit:=wdStory
WdSel.InsertBefore Msg


The format of the body line controls where the date is inserted
Code:
Sub StampDate()
Set Item = Application.ActiveInspector.currentItem
' first line
 '  Item.Body = Format(Date, "mm/dd/yyyy", vbUseSystemDayOfWeek, vbUseSystem) & vbCrLf & vbCrLf & Item.Body

'last line
   Item.Body = Item.Body & vbCrLf & vbCrLf & Format(Date, "mm/dd/yyyy", vbUseSystemDayOfWeek, vbUseSystem)
End Sub
 

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
you need to move the cursory to the end -
WdSel.EndKey Unit:=wdStory
WdSel.InsertBefore Msg
I do not know where to put this in the macro or what to replace PLS help.
Can you Pls put it in the macro I have posted?

If I use your macro
Sub StampDate()
The formatted body get lost!
e.g. lines in red get black again and format is lost!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Try HTMLBody instead of just Body.

You'd use my StampDate macro in place of your AddNote macro.


To keep using your macro, you need to add WdSel.EndKey Unit:=wdStory before the insertbefore line in your macro

WdSel.Start = 0
WdSel.End = 0
WdSel.EndKey Unit:=wdStory
WdSel.InsertBefore Msg
WdSel.Start = WdSel.Start + p
WdSel.End = WdSel.Start
End Sub
 

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
when I use StampDate macro

Code:
Sub StampDate()
Set Item = Application.ActiveInspector.CurrentItem
' first line
'  Item.Body = Format(Date, "mm/dd/yyyy", vbUseSystemDayOfWeek, vbUseSystem) & vbCrLf & vbCrLf & Item.Body

'last line
   Item.HTMLBody = Item.HTMLBody & vbCrLf & vbCrLf & Format(Date, "mm/dd/yyyy", vbUseSystemDayOfWeek, vbUseSystem)
End Sub

1605034312768.png

1605034374176.png

Is Something wrong in the code?

I found this - loosing format:

What to try next?
 
Last edited:

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
To keep using your macro, you need to add WdSel.EndKey Unit:=wdStory before the insertbefore line in your macro

WdSel.Start = 0
WdSel.End = 0
WdSel.EndKey Unit:=wdStory
WdSel.InsertBefore Msg
WdSel.Start = WdSel.Start + p
WdSel.End = WdSel.Start
End Sub
This works BUT
The next problem is that the focus is not at the cursor!
Meaning when I start to write the letters go There Were the cursor was before starting the macro.!

How to set the focus to the cursor position where the macro puts it?
 
Similar threads
Thread starter Title Forum Replies Date
R Disable conversation thread from replying of recipients in the same subject. Please help Using Outlook 0
R seperate read layout to design in outlook 2016..Help!! Outlook VBA and Custom Forms 3
O Help .. got lost ... installing Office like 2016 Using Outlook 5
A Arthur needs help with 2007 Outlook e-mail Using Outlook.com accounts in Outlook 3
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
Marc2019 Need help please! Cannot Setup my outlook email account on my Mac Outlook 2011 Using Outlook.com accounts in Outlook 2
L Attachment saving and tracking - PLEASE help! Outlook VBA and Custom Forms 5
I Help with dates in task list. Using Outlook 5
C need help setting up outlook first time Using Outlook 1
K To do bar help Using Outlook 8
M Help sending email but removing signature via VBA Outlook VBA and Custom Forms 5
S help with outlook scripting Outlook VBA and Custom Forms 4
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
EmelineGueguen Help to understand the problem of work Using Outlook 1
N Outlook Forms Help Outlook VBA and Custom Forms 2
N Need help syncing contacts to iPhone X Using Outlook 8
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3
broadbander Needing help with reply/reply all while keeping attachments and adding a new CC recipient. Outlook VBA and Custom Forms 5
J Help! My contacts have disappeared. Using Outlook 5
J HELP- Rule to auto strip prepend from external emails Using Outlook 0
J Help Needed With Multi-Step Login Email Address Using Outlook.com accounts in Outlook 1
G Bcc help - Preventing multiple forwards from a bcc'd distribution group Using Outlook 1
G [Help] Converting array to destination folder path Outlook VBA and Custom Forms 1
K Help.... Office Outlook 2016 Using Outlook 1
S Error using AddressEntry.GetContact - need help Outlook VBA and Custom Forms 2
D Help with code to move mail on receipt to another folder based on time received Outlook VBA and Custom Forms 2
EaglePI Outlook 2010 need help with rules Using Outlook 0
B HELP! Using Outlook 4
Jeff Davis Help fix my Outlook 2013? Using Outlook 28
M Winmail. dat - HELP Using Outlook 2
Diane Poremsky Help! My Contacts are being updated! New Slipstick.com Articles 0
B VBA Help Email that will save as draft and send as attachment Outlook VBA and Custom Forms 3
J Can Anyone Help?? Outlook VBA and Custom Forms 1
C Newbie needs help with Outlook Macro Outlook VBA and Custom Forms 3
B Need Help - Willing to pay Outlook VBA and Custom Forms 10
D help with Item/Inspector close event Outlook VBA and Custom Forms 1
G Looking for help with our Organization Forms Library Outlook VBA and Custom Forms 1
J Need Help with Contacts VBA Outlook VBA and Custom Forms 1
L Outlook 2002: HTML Emails Will Not Print: Please Help Using Outlook 0
H Need help setting up GetFolderPath-Makro with Vodafone IMAP Mail-Account Outlook VBA and Custom Forms 0
A newb outlook macro help Outlook VBA and Custom Forms 1
T Need help with finding/updating task Outlook VBA and Custom Forms 1
X Help with custom form which is very similar to Tasks Outlook VBA and Custom Forms 6
joflo copy contents from outlook to excell - please help. Using Outlook 4
P Outlook 2010: Missing tab - "Format/Picture Tools" HELP! Using Outlook 3
L Looking for help - want to try an alternative to Outlook? Outlook Wishlist 0
M Help! Can't set up IMAP for gmail Using Outlook 2
A Help with VBA please! Outlook VBA and Custom Forms 15
E Outlook Contacts Help Using Outlook 1
G Message template / custom forms and VBA Help needed - inserting info into table Outlook VBA and Custom Forms 3

Similar threads

Top