XL97: UserControl Property Code Example Doesn't Work Properly

Last reviewed: March 13, 1998
Article 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

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.

Microsoft provides examples of Visual Basic for Applications procedures 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

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" (without the quotation marks) 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 : kbcode kbprg xlvbahowto xlvbainfo xlhelp
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbdocerr


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 13, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.