Here Is a code that does that:
Code:
Public Sub AddDateEnd()
Dim olItem As ContactItem
Dim olInsp As Inspector
Dim wdDoc As Object
Dim oRng As Object
On Error Resume Next
Select Case Outlook.Application.ActiveWindow.Class
Case olInspector
Set olItem = ActiveInspector.CurrentItem
Case olExplorer
Set olItem = Application.ActiveExplorer.Selection.Item(1)
End Select
With olItem
.Display
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
Set oRng = wdDoc.Range
If Len(oRng) > 2 Then
oRng.Collapse 0
oRng.Text = vbCrLf
End If
oRng.Collapse 0
oRng.Text = vbCrLf & Format(Date, "mm/dd/yyyy") & "-" & Format(Time, "HH.MM ") & " Call: "
oRng.Paragraphs(2).Range.Font.Color = RGB(0, 128, 0) 'green
' Goal -- place the cursor at the end of what has been inserted to be able to start writing
oRng.Collapse 0
oRng.Select
'.Save 'saving manualy With Save& close
'.Close 0 'Do not Close for further inserting text there
End With
lbl_Exit:
Set olItem = Nothing
Set olInsp = Nothing
Set wdDoc = Nothing
Set oRng = Nothing
Exit Sub
End Sub
BUT:
1. This does not run in the VBScript editor with the button!
So I ask for the code or Procedure to start This macro with the button in the form.
2. This macro inserts DATE - Time & MESSAGE: at the end of an Outlook contact form.
This is working fine so far. But after handling this, I have no "real" focus, which means when I press any key, nothing is typed to the body. I can see the cursor but it is not blinking. Hope you understand what I mean.
The cursor is still in this field or position where it was before starting the macro
How to set focus there to be able to start writing after running the macro
I hope my aim is clearer now?
Possible solution:
1) change the code that it is running in the form with button
advantage the focus can be set via sendkeys
because I know the tab position of the button
e.g.
Code:
Sub Telefon_Click()
Item.Body = Item.Body & vbCrLf & Date() & " - " & FormatDateTime(Time,4) & " Anruf " + strUser + ": " & vbCrLf
Set objWSHShell = CreateObject("WScript.Shell")
objWSHShell.SendKeys("{TAB 10}")
objWSHShell.SendKeys("^{End}")
objWSHShell.SendKeys("^{backspace}")
End Sub
This does exactly what I want
BUT
is ruining the HTML body with formatted body content
I tried HTML.body = not supported?
or I did something wrong!
2) start the VBA code With button in the form
Problem 1 No code or procedure to Start the macro with the button
Problem 2 No focus at courser position after executing the macro
In fact the task is:
Run a macro that inserts
Date & Time & Message at the
end of the body of an OL contact form and
sets focus on the cursor there to be able to start writing after running the macro
AND NOT losing the formatted body (colors, links etc..)
Sounds quite simple!
Maybe my approach in archiving this is totally wrong!!??
What do You Think?
What is the way to achieve this?
I hope for further help on this.
THX