Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 23

Thread: Start a macro with a button in outlook userdefined contact form

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

    Question Start a macro with a button in outlook userdefined contact form

    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!

    ol VB code editor.jpg


    Sub CommandButton4_Click()
       CODE NEEDED! 
    End Sub
    The macro is in module 2. Name:

    Public Sub AddNote()

    It sets the cursor at the end of the body of the contact form:
    If I get help here:
    http://www.vbaexpress.com/forum/show...k-contact-body

    Do I need some more libraries to get this work?

    OL Verweise.jpg
    Last edited by Witzker; 11-06-2020 at 07:03 AM.

  2. #2
    VBAX Regular
    Joined
    May 2018
    Posts
    50
    Location
    Sounds quite simple!?

    BUT No answer here?

    Can You please be so kind and recommend another forum for this question?y
    THX

  3. #3
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    Right click the button and select ASSIGN MACRO. Choose the macro name from the list that is presented and click OK.

  4. #4
    VBAX Regular
    Joined
    May 2018
    Posts
    50
    Location
    Quote Originally Posted by Logit View Post
    Right-click the button and select ASSIGN MACRO. Choose the macro name from the list that is presented and click OK.
    THX BUT we are in OUTLOOK Contact Form!
    Start a macro with a button in outlook userdefined contact form

    There is no functionality like this!

    Right Click on Button in edit made.png

    Or have I missed Something?

    What I need is the code in the Form:

    Sub CommandButton4_Click
    code needed!!!
    End Sub

    PLS SEE Above where it is!
    Last edited by Witzker; 11-11-2020 at 08:06 AM.

  5. #5
    VBAX Regular
    Joined
    May 2018
    Posts
    50
    Location
    Quote Originally Posted by Logit View Post
    Right click the button and select ASSIGN MACRO. Choose the macro name from the list that is presented and click OK.
    Can you please post a screenshot!!

    I cannot find this not even in word or excel button
    üls describe the steps how you get there!

    Im on Office 2019

  6. #6
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    .
    Using the image in your first post above ... you have apparently created a COMMANDBUTTON4.
    The code that runs, when you click this button, is located in that area.

    What it should look like is :

    Sub Commandbutton4_Click ()
    
    End Sub
    If you wanted to run a macro named ThisIsMyMacro :

    Sub ThisIsMyMacro ()
         'code for this macro goes here
    End Sub
    Then the code for the button would be :


    Sub Commandbutton4_Click ()
    ThisIsMyMacro
    End Sub

  7. #7
    VBAX Regular
    Joined
    May 2018
    Posts
    50
    Location
    THX for taking care!

    Does this work on your Outlook?

    This is the macro in DieseOutlookSitzung
    Hello in This OLsession.png

    I'm on OL 2019 and tried the following without success:

    5 Buttons ERRORS1.jpg

    Do I need some more libraries to get this work?
    Pls see above what is enabled at the moment!
    Attached Images Attached Images
    Last edited by Witzker; 11-12-2020 at 11:33 AM.

  8. #8
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    .
    Attached Images Attached Images

  9. #9
    VBAX Regular
    Joined
    May 2018
    Posts
    50
    Location
    YOU ARE in EXCEL!!!

    I'm speaking of a button in OUTLOOK CONTACT FORM
    PLS see above!

    I attach my TestMacro Form for outlook!

    Can you pls try if it works?
    Attached Files Attached Files

  10. #10
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    .
    I receive the same errors here as you did there.

    Change the coding in CommandButton1. Make it read :

    Sub CommandButton1_Click
         MsgBox "Hello, this is Button 1"
    End Sub
    Then run the form and click button one.

  11. #11
    VBAX Regular
    Joined
    May 2018
    Posts
    50
    Location
    Quote Originally Posted by Logit View Post
    .
    I receive the same errors here as you did there.

    Change the coding in CommandButton1. Make it read :

    Sub CommandButton1_Click
         MsgBox "Hello, this is Button 1"
    End Sub
    Then run the form and click button one.

  12. #12
    VBAX Regular
    Joined
    May 2018
    Posts
    50
    Location
    OK THX for taking care BUT this is NOT the big aim to have a button in OL contact form saying "Hello World"!

    The aim is as described several times to start A MACRO!! (written In VBA what is clear!) With a Button in OL contact form!

    FYI: VBA is NOT supported in the CODE OF THE OL CONTACT FORM (IT SUPPORTS only VB)

    meaning a macro in VBA like:
    http://www.vbaexpress.com/forum/show...k-contact-body

    Will NOT run in VB code of the form!!

    I hope my question is now understandable here!

    SO THX BUT still the same Question from my first post!
    Last edited by Witzker; 11-12-2020 at 02:24 PM.

  13. #13
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    .
    The following shows you can run a macro from one of the CommandButtons on the form. Regretfully, I am not familiar with the Outlook VB programming. Perhaps someone else can assist who is knowledgeable.

    Public Sub CommandButton1_Click()
        	Call AddDateEnd
    End Sub 
    
    
    Public Sub AddDateEnd()
    'Dim olItem As ContactItem 
    'Dim olInsp As Inspector 
    'Dim wdDoc As Object
    'Dim oRng As Object 
    
    
    MsgBox "Hello"
    
    
        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 = Format(Date, "mm/dd/yyyy") & " Call:" & vbCrLf & Format(Time, "HH.MM ")
            oRng.Paragraphs(1).Range.Font.Color = RGB(0, 128, 0)    'green
            ' place the cursor at the end of what has been inserted to be able to start writing
            oRng.collapse 0
            oRng.Select
            .Save
            '.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

  14. #14
    VBAX Regular
    Joined
    May 2018
    Posts
    50
    Location
    THX
    Can You please tel me where this code should go?

    In ThisOutlooksession?
    In the code of the form?

    Is it working on your outlook in my attached MakroTest form?

  15. #15
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    You already have the code for the CommandButtons. Did you create the code for that ?

    If so, the code goes in the same location.

    Advise if you did not write the code for the CommandButtons.

  16. #16
    VBAX Regular
    Joined
    May 2018
    Posts
    50
    Location
    THX for Taking Care

    I have put the whole code you posted in the VB editor in the OL Form where the command buttons are defined.

    When I click the Button
    HELLO is shown when I click OK

    Nothing more happens!
    BUT also no ERROR
    ------------------------------

    Maybe is best to scratch from SCRATCH?

    What I want to achieve is

    When I click the button in the OL Contact Form
    DATE – TIME & MESSAGE:
    should be inserted at the end of the Body in blue
    And the cursor should go to the end of the inserted Text to be able to start writing there.

    I hope I have described to be understandable!

    Contact form Insert Date.jpg


    Last edited by Witzker; 11-13-2020 at 10:24 AM.

  17. #17
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    .
    I understand your goal. Sadly, I do not understand the VB code required for Outlook.
    If it accepted VBA code ... I could help ... but ... it does not accept VBA code.

    Can anyone else assist with his needs ?

  18. #18
    VBAX Regular
    Joined
    May 2018
    Posts
    50
    Location
    THX

    There is the problem!

    I think the macro cannot run in VB

    Therefore, I thought I is a good idea to cal the VBA macro with VB code of the form.

    I think I had this work years ago in OL 2003 or so.

    Maybe Microsoft has blocked executing something like this, so I have edit registry or a Library is missing.

    TERRIBLE

  19. #19
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    .
    I believe you can accomplish your goal by using the correct programming language for Outlook.
    Surely there must be websites with resources pertaining to the Outlook Programming Language that will assist.
    I haven't done a search but ...

  20. #20

Tags for this Thread

Posting Permissions

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