Consulting

Results 1 to 11 of 11

Thread: Sleeper: 'New Outlook' Broken my VBA

  1. #1
    VBAX Regular
    Joined
    Feb 2020
    Posts
    19
    Location

    Sleeper: 'New Outlook' Broken my VBA

    Good Morning All.

    Hopefully this will be a quick one.

    Op: Office365 (enterprise)
    Outlook: version 2303 (16227.20280)

    The Problem.

    Having developed and running the workbook withou issue for about 12months it has now started erroring.

    At the startup of the workbook the users email address is got (to both log and send messages in the background redaing selections they make).
    To stop it falling over, i added a line to check if outlook is running, and if not tell them it needs to be and then closes the book.
    (Code below).

    Now with the recent release of 'New Outlook' (toggle)

    If I have this version of outlook running instead, [which I quite like], then the code line does not see outlook as running?!? (and therefore doenot pick up the users email either)

    Any suggestions why this might be would be great, would like to get something inplace before work pushes the release out formally.

    cheers.
    M.

    TLDR: If current Outlook is open oOutlook NOT Nothing; if New Outlook is open, oOutlook IS Nothing; if Outlook is closed, oOutlook IS Nothing.

    The Code:

    Public Sub email_hunter()
    Dim oOutlook As Object 'Checks Outlook is open.
    On Error Resume Next
    Set oOutlook = GetObject(, "Outlook.Application")
    On Error GoTo 0
    If oOutlook Is Nothing Then
    MsgBox "Outlook is not open, open Outlook and try again. " & vbNewLine & vbNewLine & _
    "'New Outlook' does not work either(PreRelease)" & vbNewLine & vbNewLine & _
    "Please open Outloook email and try again."
    ActiveWorkbook.Close SaveChanges:=False
    Else
    Call mod_MISC.currentUserEmailAddress
    USER_email = currentUserEmailAddress
    End If
    end sub

  2. #2
    You can try this code:
    ' https://social.msdn.microsoft.com/Forums/en-US/93674f48-299e-4880-b77f-5f7bc66b2e75/names-of-currently-running-applications?forum=isvvba
    Public Function IsProgramOpen(ByVal program_name As String) As Boolean
    ' Arnelgp
    '
    ' Example:
    '
    ' test if Outlook is already running
    '
    '   ? IsProgramOpen("OUTLOOK.EXE")
    '
    ' some common program names:
    '
    ' "OUTLOOK.EXE"     to test for Outlook is already running
    ' "MSACCESS.EXE"    to test if MS Access is already running
    ' "EXCEL.EXE"       to test for Excel
    ' "WINWORD.EXE"     to test for Word application
    ' "POWERPNT.EXE"     to test for Powerpoint
    '
    ' etc.
    '
     Const THIS_PC As String = "."
     Dim objWMIService, colItems, objItem
     Dim sName As String
    
    
        Set objWMIService = GetObject("winmgmts:\\" & THIS_PC & "\root\CIMV2")
        Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process", , 48)
    
    
        program_name = UCase(program_name)
        
        For Each objItem In colItems
            sName = UCase(Trim$(objItem.Name))
            If sName = program_name Then
                IsProgramOpen = True
                Exit For
            End If
        Next
    End Function
    on immediate window (VBA) you test:

    ?IsProgramOpen("OUTLOOK.EXE")

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    This is a snippet I use to send Outlook emails

    Uses Outlook if open, opens Outlook if not


        'open Outlook or create if not open
        On Error GoTo OutlookError
        Set oOutlook = GetObject(, "Outlook.Application")
        On Error GoTo 0
    
    .......    
    
    
        Exit Function
    
    
    OutlookError:
        If Err.Number = 429 Then
            Set oOutlook = CreateObject("Outlook.Application")
            Resume Next
        Else
            SendWithOutlook = False
    
    
        End If
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Regular
    Joined
    Feb 2020
    Posts
    19
    Location
    Thanks for the replies.

    Interestingly and looking into TM a bit more, the 'New Outlook' runs as olk.exe

    still trying to work out what the > Set oOutlook = GetObject(, "Outlook.Application")
    command is for this alternative.

    but for now I am using your [Arnalgp] function checking for true in either OLK.EXE or OUTLOOK.EXE

  5. #5
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    As far as I can see, the new outlook seems to be more of an app with no VBA support. (if memory serves, wasn't olk.exe the old outlook express executable? If so, hardly "new outlook" )
    Be as you wish to seem

  6. #6
    VBAX Regular
    Joined
    Feb 2020
    Posts
    19
    Location
    Just a quick update. - I'll leave it as open for now without solution, although it looks like it may not be possible.

    I implemented program check function suggested with an or statement picking up either version.
    However, although it accepts the OLK as true, i does'nt pull the needed info (Users email address and line manager), nor does it send any messages, just loads them as draft emails then sends when outlook(.exe) opens.

    Back to the drawing board, may for now just have to force users to open the original outlook rather than the new fangled preview - see what happens when it comes out into formal release and hope a proper hand off is established.

  7. #7
    Nice update. Let me see your results.

  8. #8
    Announce me when you have the results.

  9. #9
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,054
    Location
    @ Hilltroop, Try being polite about your requests.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  10. #10
    VBAX Newbie
    Joined
    Nov 2023
    Posts
    1
    Location
    One potential solution is to use the CreateObject function instead of GetObject.wordle

  11. #11
    Banned VBAX Newbie
    Joined
    Nov 2023
    Posts
    2
    Location
    Try checking for both versions of Outlook to cover all scenarios.

    On Error Resume Next
    Set oOutlook = GetObject(, "Outlook.Application")
    On Error GoTo 0
    If oOutlook Is Nothing Then
    ' Try to get the new Outlook
    On Error Resume Next
    Set oOutlook = GetObject(, "Outlook.Application.23")
    On Error GoTo 0
    End If
    Last edited by Aussiebear; 11-28-2023 at 12:48 AM. Reason: Removed the spam link

Posting Permissions

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