Share via


Visual Basic Concepts

Converting Existing Applications into ActiveX Documents

You may have several existing applications that are candidates for conversion into ActiveX documents. If so, you can use the ActiveX Document Migration Wizard to ease the transition.

Note   The OLE Container control and embedded objects (for example, Microsoft Word or Microsoft Excel documents) cannot be placed on an ActiveX document, and will be removed.

To use the ActiveX Document Migration Wizard

  1. Open the project you wish to convert.

  2. On the Add-Ins menu, click Add-In Manager.

  3. Highlight VB ActiveX Document Migration Wizard, click the desired behaviors in Load Behavior, and then click OK.

  4. On the Add-Ins menu, click ActiveX Document Migration Wizard.

  5. Follow the directions until the Wizard has finished its task.

What the Wizard Does

The Wizard performs the following tasks

  • Copy form properties to a new UserDocument.

  • Copy all controls from the form to the UserDocument, and retain their names.

  • Copy all code behind the form to the UserDocument.

  • Comments out all illegal code such as Me.Left and End.

  • Switches the project type to ActiveX EXE or DLL.

  • Where there is an exact counterpart on the UserDocument, copy event handlers to the UserDocument, replacing "Form" with "UserDocument". For example, "Form_Click()" becomes "UserDocument_Click()". In cases where there is no counterpart, the event handler is copied over leaving the "Form" part intact. These are copied to the General section of the code window, and can then be called as procedures. In other words, if you need to invoke code from the Form_Load event, simply call it from an appropriate event:

    Private Sub UserDocument_Show()
        Form_Load
    End Sub
    

Note   The Form object's Load event doesn't have a direct counterpart in the UserDocument. You place Load event procedures in the Show event handler, but you should be aware that the Show event gets called every time the user navigates to the ActiveX document (in a Web browser). To prevent Load event procedures from running every time the Show event occurs, use a module-level variable as a flag — if the flag has been set, don't run the procedures. Code for this technique is shown in "Determining the ActiveX Document's Container Programmatically" in this chapter.