none
execute VBA in command line RRS feed

  • Question

  • Hello,

    I want to change execute this VBA by comman line because i must make a Schedule.

    The solution is to start the VBA when i start Outlook and make a Schedule for open and close Outlook but it's not very well.

    Is it possible to execute it by command line ?

    This littel script modify the "display as" in contact Outlook.

    Public Sub ChangeEmailDisplayName()
        Dim objOL As Outlook.Application
        Dim objNS As Outlook.NameSpace
        Dim objContact As Outlook.ContactItem
        Dim objItems As Outlook.Items
        Dim objContactsFolder As Outlook.MAPIFolder
        Dim obj As Object
        Dim strFirstName As String
        Dim strLastName As String
        Dim strFileAs As String

        On Error Resume Next

        Set objOL = CreateObject("Outlook.Application")
        Set objNS = objOL.GetNamespace("MAPI")
        Set objContactsFolder = objNS.GetDefaultFolder(olFolderContacts)
        Set objItems = objContactsFolder.Items

        For Each obj In objItems
            'Test for contact and not distribution list
            If obj.Class = olContact Then
                Set objContact = obj

              With objContact

              If .Email1Address <> "" Then
                ' Uncomment the  strFileAs line for the desired format
                ' Add the email address to any string using
                ' the following code:
                ' & " (" & .Email1Address & ")"

                 'Firstname Lastname (email address) format
                 ' strFileAs = .FullName & " (" & .Email1Address & ")"

                 'Lastname, Firstname format
                  strFileAs = .FullName & " (" & .Email1Address & ")"

                 'Company name (email address) format
                 ' strFileAs = .CompanyName & " (" & .Email1Address & ")"

                 'Comapany Firstname Lastname (email address) format
                 'the display name will have a leading space if
                 'the contact doesn't have a company name
                 'strFileAs = .CompanyName & " " & .FullName & " (" & .Email1Address & ")"



                 'File As format
                 'Does not support Company (Fullname) format.
                 'Only Company name is used in the display name
                 'strFileAs = .FileAs

                 .Email1DisplayName = strFileAs

                 .Save
               End If
              End With
            End If

            Err.Clear
        Next

        Set objOL = Nothing
        Set objNS = Nothing
        Set obj = Nothing
        Set objContact = Nothing
        Set objItems = Nothing
        Set objContactsFolder = Nothing
    End Sub

                                                                                                                          
    Friday, August 14, 2015 12:18 PM

Answers

  • You need to convert your VBA script to VBScript. You can then invoke it with a command line.
    • Proposed as answer by Mike Laughlin Friday, August 14, 2015 3:10 PM
    • Marked as answer by Bartoch Wednesday, September 2, 2015 9:24 AM
    Friday, August 14, 2015 1:43 PM

All replies