Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Error message when you use the NewWindow method to return boolean values: "Run-time Error '438'"


View products that this article applies to.

This article was previously published under Q282165

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


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 Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS
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.

↑ Back to the top


Keywords: KB282165, kbprb, kbpending, kberrmsg

↑ Back to the top

Article Info
Article ID : 282165
Revision : 6
Created on : 1/29/2007
Published on : 1/29/2007
Exists online : False
Views : 281