Consulting

Results 1 to 9 of 9

Thread: Code to put Date & Time at the bottom of a user Contact form in OL 2010

  1. #1
    VBAX Regular
    Joined
    May 2018
    Posts
    50
    Location

    Question Code to put Date & Time at the bottom of a user Contact form in OL 2010

    Hi
    I have this code to put Date & Time at the bottom of a user Contact form in OL 2010 and put the cursor there.
    the code ist started with a button in the form (vba or vbscript?)

    Sub Datum_Click()
    Item.Body = Item.Body & vbCrLf & Date() & " - " & FormatDateTime(Time,4) & ": "
    Set objWSHShell = CreateObject("WScript.Shell")
    objWSHShell.SendKeys("{TAB 11}")
    objWSHShell.SendKeys("^{End}")
    objWSHShell.SendKeys("^{backspace}")

    It would be great if this line would apear in Red in the form.

    Can You pls asist?

  2. #2
    Try the following

    Dim olInsp As Outlook.Inspector
    Dim wdDoc As Object
    Dim oRng As Object
        With Item
            .Display
            Set olInsp = .GetInspector
            Set wdDoc = olInsp.WordEditor
            Set oRng = wdDoc.Range
            oRng.collapse 0
            oRng.Text = vbCr & Date & " - " & FormatDateTime(Time, 4) & ": "
            oRng.Font.Color = &HFF
            oRng.collapse 0
            oRng.Select
        End With
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    May 2018
    Posts
    50
    Location
    I put this in diese Outlook Sitzung

    Public Sub DateRed()

    Dim olInsp As Outlook.Inspector
    Dim wdDoc As Object
    Dim oRng As Object
    With Item
    .Display
    Set olInsp = .GetInspector
    Set wdDoc = olInsp.WordEditor
    Set oRng = wdDoc.Range
    oRng.Collapse 0
    oRng.Text = vbCr & Date & " - " & FormatDateTime(Time, 4) & ": "
    oRng.Font.Color = &HFF
    oRng.Collapse 0
    oRng.Select
    End With
    End Sub




    when I open a contact and run it it says Objekt benötigt

  4. #4
    I assumed that you had already declared what 'Item' was You have to tell they macro what 'Item' is e.g.

    Public Sub DateRed()
    Dim Item As Object
    Dim olInsp As Outlook.Inspector
    Dim wdDoc As Object
    Dim oRng As Object
        Set Item = ActiveExplorer.Selection.Item(1)
        If TypeName(Item) = "ContactItem" Then
            With Item
                .Display
                Set olInsp = .GetInspector
                Set wdDoc = olInsp.WordEditor
                Set oRng = wdDoc.Range
                oRng.collapse 0
                oRng.Text = vbCr & Date & " - " & FormatDateTime(Time, 4) & ": "
                oRng.Font.Color = &HFF
                oRng.collapse 0
                oRng.Select
            End With
        Else
            Beep
        End If
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Regular
    Joined
    May 2018
    Posts
    50
    Location
    Great THX

    I added
    oRng.Text = vbCr & Date & " - " & FormatDateTime(Time, 4) & " Anruf: "

    is it also possible to start the Telephone dialog from outlook with this macro?

  6. #6
    If it is possible I don't know how to do so and can find no on-line reference to the dialog.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  7. #7
    VBAX Regular
    Joined
    May 2018
    Posts
    50
    Location
    is it Possible to set the cursor at the end of the inserted date?

    oRng.Text = vbCr & Date & " - " & FormatDateTime(Time, 4) & " Anruf: "

    to write ther a coment

  8. #8
    oRng.collapse 0
    oRng.Select
    as in the original macro should do that.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  9. #9
    VBAX Regular
    Joined
    May 2018
    Posts
    50
    Location

    Question

    Yes

    The text is inserted in red and is displayed at the end of the field even if there is more text in the field

    BUT

    The cursor is in another fields on the form !
    If I start writing it is in another field

    How to put cursor at the end of the inserted text in memo field?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •