HowTo start a macro with an Button in OL contact form

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
I have a user defined form in Outlook 2019

I have created a button and want to know how I can start a macro by pressing this button in the form?
The code for the button is in the Outlook forms VBScript editor!
1604708853201.png


Code:
Sub CommandButton4_Click()
   CODE NEEDED!
End Sub

The macro is in module 2. Name:

Public Sub AddNote()

Do I need some more libraries to get this work?

1604708973681.png


Hope for Help
 
You want to start the AddNote macro by clicking commandbutton4?

Try using Call AddNote - but you also need to adjust security settings so the script will run.
You may need to have the AddNote macro in the script editor rather than as VBA.

You need to set some registry keys to use vbscripts.
 
THX for taking care
At the moment I have exactly the problem you mentioned on my new computer with Win 10 prof (latest updates) and Office 2019
I have tied the fixes BUT nothing works in the form.
Other macros are ok

Is there something different in OL2019 to 2016 (which is described)?
Maybe some policy rules?
 
you need to enable the registry keys for the custom forms. I used the sample reg file for 2016 (it works for 2019/365 too) when I tested it last night - that will allow run this form to work for testing. I wasn't able to call a vba macro but could call ones in the script editor.

I thought we could call macros but its been so long since I needed to do anything like that, that I forget. :)
 
YES !
THX I used your code in your perfect description.
I forgot to put also the standard contact item there.
With the .reg file it st working now.

Could you Pls be so kind and look at this macro:

I do not understand it I think there is not too many corrections to put the date & message not on TOP but at the BOTTOM of the body.

This macro should run on 3-4 buttons in the contact form with different messages.

Maybe we get the macro first then try to start it with the buttons.
What do you think?

I thought we could call macros but its been so long since I needed to do anything like that, that I forget.
I hope you will remember
 
THX for the macro - There is still a problem with focus on cursor Pls see here:

But To go on With starting the macro:
I hope you will remember HowTo!

The macro for testing is in ThisOutlookSession ( in German version DieseOutlookSizung)

Hello in This OLsession.png


What I tried in the meantime:
5 Buttons ERRORS1.jpg

What's the matter here?
Do I need some more libraries
1605206342369.png


Or has Microsoft also blocked something that Prevents the macro to be called and from running

Does this work in Your Outlook?
I have attached the test Form MakroTest in zip

I'm now on OL 2019

Hope for Your Help
 

Attachments

Last edited:
I found This

But I do not Know HowTo

in fact, it is like calling a macro from VBS script which should be possible
here is als somethin that calls a macro from ThisOutlooksession but i do not understand howTo adapt this for calling it witz my button

I hope you will remember HowTo
 
You can call macros from VBA - but not from the vbscript in a form. (VBA and vbscript are two different programming languages).

The stackoverflow question is calling it from task scheduler, not a form.
 
Here Is the demand.

How can I achieve this?

Macro To add Date-Time & Message.jpg


Hope you can help maybe with another solution with same result
THX

VBA and vbscript are two different programming languages).
Qs I understand I cannot cal a Macro in vbcript
But can I have this insert function written in vbscipt?
Are there other ways to get this Date & message inseted?
 
Hi
I have a user defined form in Outlook 2019

I have created a button and want to know how I can start a macro by pressing this button in the form?
The code for the button is in the Outlook forms VBScript editor!
View attachment 3137

Code:
Sub CommandButton4_Click()
   CODE NEEDED!
End Sub

The macro is in module 2. Name:

Public Sub AddNote()

Do I need some more libraries to get this work?

View attachment 3138

Hope for Help
You want to start the AddNote macro by clicking commandbutton4?
 
You want to start the AddNote macro by clicking commandbutton4?
THX for taking care
YES! Like shown on The picture above
Command button Nr is not important!

In Fact, I need code to start a VBA macro that puts the cursor in the body field of the contact form and adds something!

OR a code that can be executed in the form itself directly with the command button

I hope the aim is Clear?
 
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
 
Last edited:
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Witzker HowTo Change message Class of contact form Outlook VBA and Custom Forms 0
M Outlook2007 and VSTO, handle the Click on the Save Button in the IPM.Note dialog HOWTO? Outlook VBA and Custom Forms 4
M Start Outlook 365 at unified inbox Using Outlook 2
Fozzie Bear Calendar Events created on iPhone have suddenly start sending invitations to attendees Using Outlook 2
D Unable to change AppointmentItem.Start property Outlook VBA and Custom Forms 3
R unable to filter tasks when start date is on or before today Using Outlook 4
O Outlook 365 - Gmail and Outlook: how to force Outlook to start up in Gmail? Using Outlook 2
S Change "This Week" flag start date behavior Using Outlook 1
W Recurrence: delete older occurrences / change earliest start time Outlook VBA and Custom Forms 0
V Change start time based on message duration Outlook VBA and Custom Forms 2
A End-time meeting reminder (or "negative" time relative to the meeting start time) Using Outlook 1
N Multiple instances of Outlook on Start Menu Using Outlook 2
P Automate Outlook Start - No Active Explorer Object Found Using Outlook 10
P Outlook 2016 won't Start Using Outlook 3
M Outlook 2013 fails to start -- missing WindowsCodecs.dll error Using Outlook 3
O Outlook 2016 crashes at start Using Outlook 14
S Calendar loops when clicking on calendar link to start it Using Outlook 1
L set task reminder date to same as start date (without affecting due date) Using Outlook 0
Diane Poremsky Cannot start Microsoft Office Outlook Error Message Using Outlook 0
A BCM crashes immediately after start BCM (Business Contact Manager) 2
Thorsten show the correct calendar on start Outlook VBA and Custom Forms 5
V Cannot start Outlook. Cannot open the Outlook window. Using Outlook 8
M Cannot start MS Office Outlook Cannot open the Outlook window Using Outlook 2
R Default Start time for Private Appointment Using Outlook 4
njs27 Start date of occurrence same as PatternStartDate Outlook VBA and Custom Forms 6
E Searching a Shared Outlook Mailbox from the start menu? Using Outlook 4
S Using "start application" rule action Using Outlook 2
A BCM does not start correctly BCM (Business Contact Manager) 10
M Clipboard Manager Not showing in Outlook 2010 on Start Using Outlook 8
L Outlook 2007 does not start with Apple iCloud-Add-In activated Using Outlook 2
V How can I start a NEW PST file without loosing my contacts & other data Using Outlook 3
D How do I start completely from scratch in setting up Outlook 2013? Using Outlook 6
P Outlook 2010 fails to start after icloud update Using Outlook 3
C Monday Start Monthly Template Using Outlook 0
L Change length of appointment start time Using Outlook 2
G Cannot start Microsoft Outlook Using Outlook 1
M I cannot start Microsoft Outlook 2013 directly opening a .eml message Using Outlook 1
E Adding Start and End Time to Daily View in Calendar Printing assistant Using Outlook 1
H Outlook 2010: Cannot start!, please help me! Using Outlook 3
D Task Start and Due Dates Using Outlook 3
R Changing Start Date Without Changing Due Date in Tasks Using Outlook 1
M Outlook wont start Using Outlook 1
N How can i hsve appointments and events to not display start or finish times Using Outlook 2
W Auto changing "You" at start of sentence...very frustrating! Using Outlook 4
E cannot start Microsoft Office Outlook. Cannot open the Outlook Window. Using Outlook 1
G How to NOT display the start time in monthly calendar view - 2007 Using Outlook 8
J Outlook 2010 won't start in Win 7 Using Outlook 4
S Cannot start Microsoft Office Outlook. Cannot open the Outlook window. The set of folders cannot be Using Outlook 3
S __Cannot start Microsoft Office Outlook. Cannot initialize Microsoft Office shared utilities.____ Using Outlook 4
N Start my Outlook from a server Outlook VBA and Custom Forms 1

Similar threads

Back
Top