Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2012
    Posts
    4

    Unanswered: Compile Error When Selecting A Reference

    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? I call the function to verify outlook is open before an automatic email is sent. Even when i try to use ?IsAppRunning(outlook) in the immediate window it gives me that error unless i remove the reference. 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

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try passing appString by value:
    Code:
    Set officeApp = GetObject(, ByVal(appString & ".Application"))
    Have a nice day!

Posting Permissions

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