HYPERLINK "mailto:test@test.com" in form body

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Hallo,

In my user defined form I use a macro to write text in the form body.
The code:

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 works fine but I noticed that, when I have an email address in the body, it changes from:
eg: test@test.com to: HYPERLINK "mailto:test@test.com" test@test.com
each time the button with the code is pressed
another: HYPERLINK "mailto:test@test.com" is added

are there some settings in outlook?
something wrong with the code?
How can I solve this?

Many thanks for your help.
Regards
WITZKER
 

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Thx for reply

Tried Item.HTMLBody for one and both.
Result: ERROR

Iam using german version:
Das Objekt unterstützt die Eigenschaft oder Objekt nicht
The object dosn't support attribute or objekt

Pls note the code is in the OL form Code
What I learned from other therad there is used vbscipt.

Lookin forward to a solution
 

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Diane! Great idea

As you see I'm already using sendkeys in the code to go to the bottom of the body.

It would be great if you would be so kind and let me have the code to insert the text:

vbCrLf & Date() & " - " & FormatDateTime(Time,4) & ": "

if possible also in red letters?

Regards Witzker
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Red will be complicated... and I can't get sendkeys to work at all in my test form. :(
 

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Dear Diane,

many thanks for your effort.

Is it possible to do this in a VBA macro which is located in a module instead of the code in the user definde form where only VBSkript is available?

can Item.HTMLBody be used in VBA?

If Yes what VBA code would you suggest?

The procedure for using this macro could be

open the contact
and call the macro from the ribbon.

What do you think?

Thanks Witzker
 

Forum Admin

Senior Member
Oh, yes, it will work perfectly in VBA. You'll be able to use HTMLBody, formatting the time could be easier, and you can add color. I might already have something on slipstick that comes close but I have a meeting coming up and can't look for it right now. Give me 3 or 4 hours and if I haven't updated this thread, remind me. :)
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: HYPERLINK "mailto:test@test.com" in form body

Ok... messy is my middle name :) It could be a little cleaner and neater, but it does the job.

I tweaked the macro at http://www.slipstick.com/developer/word-macro-apply-formatting-outlook-email/ to insert the date at the bottom of the page and move the cursor back to the top.

Code:
 Public Sub FormatSelectedText() 
    Dim objItem As Object 
    Dim objInsp As Outlook.Inspector 
    
   ' Add reference to Word library 
    ' in VBA Editor, Tools, References 
    Dim objWord As Word.Application 
    Dim objDoc As Word.Document 
    Dim objSel As Word.Selection 
    On Error Resume Next 
   
   
 
'Reference the current Outlook item 
    Set objItem = Application.ActiveInspector.currentItem 
    If Not objItem Is Nothing Then 
        If objItem.Class = olMail Then 
            Set objInsp = objItem.GetInspector 
            If objInsp.EditorType = olEditorWord Then 
                Set objDoc = objInsp.WordEditor 
                Set objWord = objDoc.Application 
                Set objSel = objWord.Selection 
    
   'move to end of message 
objSel.EndKey Unit:=wdStory 
 
set formatting 
       With objSel 
       ' Formatting code goes here 
            .Font.Color = wdColorBlue 
            .Font.Size = 18 
            .Font.Bold = True 
            .Font.Italic = True 
            .Font.Name = "Arial" 
       End With 
   
 
'adds a line break 
       objSel.Range.InsertParagraphAfter 
 
'inserts date & time in 3/7/2014 12:55 format 
         objSel.Range.InsertAfter "Time Stamped at " & Date & Format(Time, " hh:mm") 
    
 
' another linebreak 
    objSel.Range.InsertParagraphAfter 
 
'jump back to the top 
objSel.HomeKey Unit:=wdStory
           End If 
        End If 
    End If 
    
   Set objItem = Nothing 
    Set objWord = Nothing 
    Set objSel = Nothing 
    Set objInsp = Nothing 
End Sub
 

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Re: HYPERLINK "mailto:test@test.com" in form body

THX GREAT :)

i will adapt the code for a contct form and put it in Module 2

How can I start the macro from a custom botton in the form code

Sub CommandButton1_Click
HOW to start the macro in Module2 ??
End Sub

I hope you can let me have the code
regards
Witzker
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: HYPERLINK "mailto:test@test.com" in form body

You can use this:

Sub CommandButton1_Click
FormatSelectedText
End Sub

Or add a button to the QAT or ribbon for the macro - file, options, customize ribbon or quick access toolbar. Select Macros from the dropdown and add to the ribbon or QAt.
 

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Re: HYPERLINK "mailto:test@test.com" in form body

Thx

I have tried:
Sub CommandButton1_Click
FormatSelectedText
End Sub
in the code of custom form

also tried
FormatSelectedText()
run FormatSelectedText
run FormatSelectedText()
Error:
Typenkonflikt "FormatSelectedText"

sorry
where is the problem?

Hope for a solution
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: HYPERLINK "mailto:test@test.com" in form body

According to http://support.microsoft.com/kb/221827/ if the macro is in ThisOutlooksession and you call it using Application.macroname, it may work, but it's not recommended or supported.

- - - Updated - - -

It's not working for me in Outlook 2013.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: HYPERLINK "mailto:test@test.com" in form body

You can use this:

Sub CommandButton1_Click

FormatSelectedText

End Sub


Or add a button to the QAT or ribbon for the macro - file, options, customize ribbon or quick access toolbar. Select Macros from the dropdown and add to the ribbon or QAt.
 

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Re: HYPERLINK "mailto:test@test.com" in form body

Thx
is there another way to call a macro from ol form?
toad a field or dropdown with macros?
button wouldbe best

Hope for a solution or woraround
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: HYPERLINK "mailto:test@test.com" in form body

You can add a button to the QAT or to the ribbon. You can't make dropdown buttons, but if you need dropdowns, you can use userforms.

see How to use the VBA editor - down at the bottom is instructions to create buttons on the ribbon.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: HYPERLINK "mailto:test@test.com" in form body

You can add a button to the QAT or to the ribbon. You can't make dropdown buttons, but if you need dropdowns, you can use userforms.


see How to use the VBA editor - down at the bottom is instructions to create buttons on the ribbon.
 

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
@your post Diane
According to http://support.microsoft.com/kb/221827/ if the macro is in ThisOutlooksession and you call it using Application.macroname, it may work, but it's not recommended or supported.

in this article at the bottom is the solution to call the vba macro from the button!?:
As an alternative to calling Visual Basic for Applications code from VBScript, you can create a Visual Basic automation server, install it using a Visual Basic Setup program, and then launch the Visual Basic component by using the CreateObject method in VBScript.

Ok - but I do not understand how to do this.

I think to be able to call a VBA Macro (with all possibilities of VBA) from an OL Form with a button gives a lot possibility in realizing custom projects.

So I hope for further help on this topic.

Regards
Witzker
 

witzker

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Hi again
for the case there is really no solution to start a VBA macro with the form code I am thinking of a work around to add some buttons into the ribbon and as suggested use a user form in VB for the other macros.

First step would be following task:

I open a contact
than click on phone, to make a telephone call to the contact
Then I have to run the macro that inserts date & time and the person who called the contact in the body. (which is now working fine with your code)

It would be great when I can open the phone dialog at the beginning of the macro which inserts the date & time ....

I tried with sendkeys " STRG+Shift+D" - SendKeys "^+{D}"

I got the phone dialog open where I can start the call, but in in its window all fields are empty - meaning there is no number to call in the box.

So my question is:
If you would be so kind and let me have the code that opens the phone dialog like pressing the phon button in the ribbon of an opened contact.

Many thanks in advance
Regards
Witzker
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I'm not sure the phone dialog is accessible via VBA, but will look into it.
 
Top