Microsoft KB Archive/157555

= XL97: UserControl Property Code Example Doesn't Work Properly =

Article ID: 157555

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Excel 97 Standard Edition

-



This article was previously published under Q157555





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 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:

https://partner.microsoft.com/global/30000104

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

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
 In Microsoft Word 97, on the Tools menu point to Macro, and click Visual Basic Editor. Or, press ALT+F11. On the Insert menu, click Module.  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  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 ". When the macro is finished running, Microsoft Excel is automatically shut down.

Example Two: Set UserControl Set to True
 In Microsoft Word 97, on the Tools menu point to Macro, and click Visual Basic Editor. Or, press ALT+F11.</li> On the Insert menu, click Module.</li>  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 </li> On the Tools menu, click Macros. In the list of macros, click UserControlSetToTrue, and then click Run.</li></ol>

The macro runs and displays a message box with the message "This is Microsoft Excel, build ". 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
  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. </li> 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).</li> 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.</li></ol>

<div class="references_section">