Share via


Visual Basic Concepts

Creating the ActXDoc Project

The first step in authoring the ActXDoc project is to add a single UserDocument object to an ActiveX EXE project. A CommandButton and a TextBox control are then added to the form. Finally, using the Hyperlink object, you add code that navigates to another URL.

The step-by-step procedures in this chapter build a document object and test it in Internet Explorer, which is included with Visual Basic.

Note   This topic is part of a series that walks you through creating a sample ActiveX document. It begins with the topic Creating an ActiveX Document.

To create an ActiveX document

  1. On the File menu, click New Project to open the New Project dialog box. (This will close your current project or project group; you will be prompted to save any changes you have made.) Double-click the ActiveX Document EXE icon.

    Visual Basic automatically adds a UserDocument designer to the project. If the designer is not immediately visible, right-click over its default name, UserDocument1, in the Project Explorer window, then click View Object. When the designer appears, its default name is visible in the title bar.

  2. In the Properties window, double-click the Name property and change the name of UserDocument1 to FirstDoc. The new name appears in the title bar of the designer, and in the Project Explorer window.

  3. In the Project Explorer window, click the Project1 icon. In the Properties window, double-click Name, and change the name of the project to ActXDoc. The title bar of the designer now reads "ActXDoc - FirstDoc (UserDocument)."

  4. In the Project Explorer window, double-click the FirstDoc icon to bring it to the front.

  5. On the Toolbox, double-click the CommandButton icon to put a CommandButton control on the designer.

  6. On the Toolbox, double-click the TextBox icon to put a Textbox control on the designer.

  7. Place the two controls as shown in the following illustration:

  8. Change the appropriate properties of the two controls according to the following table:

Command1 property Value
Name cmdNavigateTo
Caption Navigate To
Text1 property Value
Name txtURL
Text https://www.microsoft.com
  1. On the FirstDoc designer, double-click the Navigate To CommandButton control to add the following code to its Click event:

    Private Sub cmdNavigateTo_Click()
       ' Use the Hyperlink object method NavigateTo
       ' to go to the URL in txtURL.
       Hyperlink.NavigateTo txtURL.Text
    End Sub
    

    Important   When using the NavigateTo method, you must include the protocol portion of the URL. For example, by default, the above code will navigate to the value of the Text property of the txtURL TextBox control — "https://www.microsoft.com".

  2. On the File menu, click Save Project to save the project files. Name them as shown in the following table. Visual Basic will provide the indicated extensions automatically.

File File name Extension
User document FirstDoc .dob
Project ActXDoc .vbp

Step by Step

This topic is part of a series that walks you through creating a sample ActiveX document.

To See
Go to the next step Running and Debugging the ActXDoc Project
Start from the beginning Creating an ActiveX Document