XL2002: Run-time Error 438 When Using NewWindow Method to Return Boolean (282165)



The information in this article applies to:

  • Microsoft Excel 2002

This article was previously published under Q282165

SYMPTOMS

When you attempt to use the results of the NewWindow method in a Microsoft Visual Basic for Applications macro or procedure in Microsoft Excel, you may receive the following error message:
Run-time error '438'
Object doesn't support this property or method
This same macro or procedure runs without error in Microsoft Excel 2000.

CAUSE

This problem can occur if you use the NewWindow method as part of an IF statement or any place you expect a Boolean value to be returned. In Microsoft Excel 2000, this method incorrectly returned a Boolean value, instead of a Window or Workbook object.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site: For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:
You can demonstrate the change in behavior by running the following Visual Basic for Applications macro in Microsoft Excel:
Sub test()
    Set w = Application.ActiveWindow
    If w.NewWindow Then
        MsgBox "Yes"
    End If
End Sub
				

In Microsoft Excel 2000, this macro runs without error. In later versions of Microsoft Excel, this macro causes a run-time error 438.

This following macro works correctly with versions of Microsoft Excel after 2000, because the NewWindow method returns an object:
Sub test2()
    Set w = Application.ActiveWindow
    Set NewWin = Nothing
    Set NewWin = w.NewWindow
    If Not (IsEmpty(NewWin)) Then
        MsgBox ("yes")
    End If
End Sub
				

However, this macro fails when you run it in Microsoft Excel 2000 or earlier, because the NewWindow method returns a Boolean value. When you run the macro, you receive the following error message:
Run-time error '13':
Type mismatch

Making your Code Work in All Versions of Microsoft Excel

If you want to use Automation with Microsoft Excel, but you do not know which version of Microsoft Excel is running, you can modify your code to work correctly with any version of Microsoft Excel.

One way to do this is to check the version of Microsoft Excel from the macro, and then store the version number in a variable. To do this, use the following line of code:
   ExcelVersion = Val(Application.Version)
				
The value of "ExcelVersion" is either 5, 7, 8, 9, or 10 for Microsoft Excel 5.0, 7.0, 97, 2000, or 2002 respectively.

After you determine the version of Microsoft Excel you are using, modify the macro to work correctly with that version of Microsoft Excel. For example, you can make the macro in this article work correctly by adding a few lines of code. The following example illustrates how to change the macro:
Sub test3()
    Set w = Application.ActiveWindow
    ExcelVersion = Val(Application.Version)
    If ExcelVersion < 10 Then
        MyBool = w.NewWindow
    Else
        Set NewWin = Nothing
        Set NewWin = w.NewWindow
        MyBool = Not (IsEmpty(NewWin))
    End If
    If MyBool Then
        MsgBox ("yes")
    End If
End Sub
This macro works correctly with Microsoft Excel 2000 or 2002.

Modification Type:MajorLast Reviewed:5/13/2002
Keywords:kberrmsg kbprb KB282165