XL97: UserControl Property Code Example Doesn't Work Properly

ID: Q157555


The information in this article applies to:
  • Microsoft Excel 97 for Windows


SYMPTOMS

In Microsoft Excel 97 Visual Basic Help, the example code provided for the UserControl property does not work properly.


CAUSE

The example code for the UserControl property assumes that the UserControl property applies to Workbook objects, when the property actually applies only to the Application object.


WORKAROUND

Instead of using the UserControl Property example, use the examples shown in the "More Information" section if you want to use the UserControl property.


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 the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp
In Microsoft Excel 97, you can use the UserControl property to determine whether or not an instance of Microsoft Excel opened through OLE Automation will continue to run when its object is released. By default, the UserControl property has a value of False.

The following examples demonstrate how you can use the UserControl property in a macro in Visual Basic or Visual Basic for Applications.

Example One: Leave UserControl Set to False



  1. In Microsoft Word 97, on the Tools menu point to Macro, and click Visual Basic Editor. Or, press ALT+F11.


  2. On the Insert menu, click Module.


  3. Enter the following code:
    
          Sub UserControlStaysFalse()
              Set xlApp = CreateObject("Excel.Application.8")
              xlApp.Visible = True
              MsgBox "This is Microsoft Excel 97, build " & xlApp.Build
              xlApp.Quit
              Set xlApp = Nothing
          End Sub 


  4. On the Tools menu, click Macros. In the list of macros, click UserControlStaysFalse, and then click Run.


The macro runs and displays a message box with the message "This is Microsoft Excel, build <xxxx>". When the macro is finished running, Microsoft Excel is automatically shut down.

Example Two: Set UserControl Set to True

  1. In Microsoft Word 97, on the Tools menu point to Macro, and click Visual Basic Editor. Or, press ALT+F11.


  2. On the Insert menu, click Module.


  3. Enter the following code:
    
          Sub UserControlSetToTrue()
              Set xlApp = CreateObject("Excel.Application.8")
              xlApp.Visible = True
              MsgBox "This is Microsoft Excel 97, build " & xlApp.Build
              xlApp.UserControl = True
              Set xlApp = Nothing
          End Sub 


  4. On the Tools menu, click Macros. In the list of macros, click UserControlSetToTrue, and then click Run.


The macro runs and displays a message box with the message "This is Microsoft Excel, build <xxxx>". When the macro is finished running, the instance of Microsoft Excel continues to run, even though the xlApp object has been released.

Notes About Using the UserControl Property

  1. When you set the UserControl property for Microsoft Excel 97 to True, you must also set the Visible property to True. For example:
    
          xlApp.Visible = True
          xlApp.UserControl = True 
    If you do not do this, you will be left with an invisible instance of Microsoft Excel. You can shut down an invisible instance of Microsoft Excel by pressing CTRL+ALT+DELETE, selecting "Excel" in the list of tasks/programs, and clicking Shut Down.


  2. The UserControl property does not apply to workbooks within Microsoft Excel 97. It applies only to the Application object itself. Because of this, you will generally not use the UserControl property within a macro unless it uses OLE Automation (either the CreateObject or GetObject) to control Microsoft Excel from another program (such as Microsoft Word 97 or Microsoft Visual Basic).


  3. The example of the UserControl property included in the Microsoft Excel Visual Basic help file is incorrect, and will not work in Microsoft Excel 97.



REFERENCES

For more information on the UserControl property of Microsoft Excel 97, type the word UserControl in a Visual Basic module. Select the word, and press F1 to view the "UserControl Property" help topic.

Additional query words: XL97 8.0 vbe

Keywords : kbprg kbdta kbdtacode KbVBA xlhelp
Version : WINDOWS:97
Platform : WINDOWS
Issue type :


Last Reviewed: November 9, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.