Compile Error When Selecting A Reference (1 Viewer)

sroot

Registered User.
Local time
Today, 10:23
Joined
Mar 18, 2013
Messages
53
Hi Guys. I have this module that works great. all it does is tell me if whatever Microsoft office program is open. The problem i get is that when i add the reference Microsoft outlook 14.0 object library i get a compile error "ByRef argument type mismatch" How can i fix this? Thanks!
Code:
Option Compare Database



    Public Enum OfficeAppName

       Outlook = 1
        PowerPoint = 2
        excel = 3
        Word = 4
        Publisher = 5
        Access = 6
    End Enum
     
    Function IsAppRunning(appName As OfficeAppName) As Boolean
    
    On Error GoTo NotRunning
     
    Dim officeApp As Object
    Dim appString As String
     
   
    IsAppRunning = True
     
   
    Select Case appName
        Case 1
           appString = "Outlook"
        Case 2
           appString = "PowerPoint"
        Case 3
           appString = "Excel"
        Case 4
           appString = "Word"
        Case 5
           appString = "Publisher"
        Case 6
           appString = "Access"
    End Select
     
    
    Set officeApp = GetObject(, appString & ".Application")
     
ExitProc:
      Exit Function
     
NotRunning:
  IsAppRunning = False
  Resume ExitProc
 
End Function
 

Rx_

Nothing In Moderation
Local time
Today, 11:23
Joined
Oct 22, 2009
Messages
2,803
Made a minor modification and it worked.
Too busy to figure out why, maybe someone else can tell me.
(use the Public Enum OfficeAppName as shown above)

Code:
    Select Case appName
        Case 1
           appString = "Outlook"
        Case 2
           appString = "PowerPoint"
        Case 3
           appString = "Excel"
        Case 4
           appString = "Word"
        Case 5
           appString = "Publisher"
        Case 6
           appString = "MSAccess"
    End Select
    Dim MyCase As String
    MyCase = appString & ".Application"
    Set officeApp = GetObject(, MyCase) ' A.K.A. "Get off of My Case"
     If Err.Number = 0 Then
        officeApp.Visible = True
    End If
ExitProc:
      Exit Function
     
NotRunning:
  IsAppRunning = False
  Resume ExitProc
 
End Function
 

sroot

Registered User.
Local time
Today, 10:23
Joined
Mar 18, 2013
Messages
53
I tried changing it but still doesn't work. It works on some of them but not all. I need it to work on outlook and that is where i am getting the error.
 

Rx_

Nothing In Moderation
Local time
Today, 11:23
Joined
Oct 22, 2009
Messages
2,803
This worked for me every time.
Does it work for you?
Is it just for your workstation or does it fail on some other workstation?

Code:
Sub TestOutlookIsOpen()
    Dim oOutlook As Object
    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"
    Else
        MsgBox "Be on outlook for an open Outlook"
    End If
End Sub
 

sroot

Registered User.
Local time
Today, 10:23
Joined
Mar 18, 2013
Messages
53
No i tired two computers and it doesnt work... it works when i uncheck that reference but once it is checked it fails
 

Users who are viewing this thread

Top Bottom