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

Status
Not open for further replies.

Witzker

Senior Member
OS Version(s)
  1. iOS
Outlook version
Outlook 2019 32-bit
Email Account
Exchange Server 2007
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
 
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
 
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!
 
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
 
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:
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?
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Witzker Outlook 2019 Pls. add a Prefix for OUTLOOK 2019 here Using Outlook 1
S Custom Contact card - need help creating one Outlook VBA and Custom Forms 1
D Lifelong Windows user - new to Mac - Help!!! Using Outlook 3
L Help: set flag for sent mail to check if received an answer Outlook VBA and Custom Forms 2
Nufc1980 Outlook "Please treat this as private label" auto added to some emails - Help. Using Outlook 4
I Help with Smart Folder + Query Builder on IMAP Using Outlook 0
S Outlook 2002- "Send" button has disappeared. Help please. Using Outlook 1
A Outlook 2019 Help with forwarding email without mentioning the previous email sender. Outlook VBA and Custom Forms 0
Witzker Outlook 2019 HELP to get Template Path in a Function Outlook VBA and Custom Forms 2
CWM330 Outlook 365 HELP! Calendar Craziness! Using Outlook 5
S Outlook 365 Help me create a Macro to make some received emails into tasks? Outlook VBA and Custom Forms 1
e_a_g_l_e_p_i Has nobody used Office 2021 enough to help me or have you given up on me.......lol Using Outlook 1
X Open Hyperlinks in an Outlook Email Message (Help with Diane's solution) Outlook VBA and Custom Forms 3
L Help connecting to hosted exchange server 2016 Using Outlook 0
B Seeking help with Outlook rule Using Outlook 2
D Need help with MS Authenticator Using Outlook 4
I Outlook for Mac 2019 using on desktop and laptop IMAP on both need help with folders Using Outlook 1
FryW Need help modifying a VBA script for in coming emails to auto set custom reminder time Outlook VBA and Custom Forms 0
S.Champ Please help? I've imported a random workcalendar I dont even know who's. Can I undo it? and then I need to re-sync the google one again. Its a mess:( Using Outlook 2
S HTML to Plain Text Macro - Help Outlook VBA and Custom Forms 1
e_a_g_l_e_p_i Outlook 2010 Help setting up Gmail account in Outlook 2010 Using Outlook 3
N Help creating a VBA macro with conditional formatting to change the font color of all external emails to red Outlook VBA and Custom Forms 5
Y Filter unread emails in a search folder vba help Outlook VBA and Custom Forms 0
L Need help modifying a VBA script for emails stuck in Outbox Outlook VBA and Custom Forms 6
F Microsoft Outlook Connector 14.0.6123.5001 - Help! Using Outlook 6
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

Similar threads

Back
Top