Home > Articles

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Using Macros

With FrontPage 2002 and Visual Basic, you can write macros that greatly simplify your work with FrontPage while also extending FrontPage's capabilities. Macros can be used to perform routine tasks automatically. You simply program the tasks that need to be performed and then run the macro.

To get started with macros, choose Tools, Macro, Macros. The Macro dialog box appears, listing all the macros you've created with VBA. At this point, of course, there are none, so the dialog box is empty.

To create a macro, you type its name in the Macro Name field and click Create. Although a detailed discussion of VBA is beyond the scope of this book, this section shows you a simple example to demonstrate the usefulness of macros.

When you run the sample macro, it displays a dialog box that tells you how many themes the current Web includes. To create your macro, type GetThemeCount in the Macro Name field and click Create.

The Visual Basic integrated development environment (IDE) opens, as shown in Figure 3.15. A new module is open within FrontPage, ready for you to add your code. Type the code shown in Listing 3.1 at the insertion point; you don't need to type the first and last lines because VBA creates those for you.

Figure 3.15 The Visual Basic for Applications IDE.

Listing 3.1 GetThemeCount Macro

Sub GetThemeCount()
Dim myWeb As Web
Dim myCount As Integer

Set myWeb = ActiveWeb

With myWeb
 myThemeCount = .Themes.Count
 MsgBox "This web contains " & myThemeCount & " theme(s)."
 
End With

End Sub

After you enter the macro code, close the code window and return to FrontPage. Choose Tools, Macro, Macros again. This time when the Macro window appears, GetThemeCount is listed there. Double-click GetThemeCount, and FrontPage displays a dialog box like the one shown in Figure 3.16.

Figure 3.16 The results of the GetThemeCount macro.

Don't forget that you also can assign a macro to any toolbar button or menu command. To do this, right-click a menu command or toolbar button while the Customize dialog box is open (or select a command or button and click Modify Selection in the Customize dialog box). On the Modify Selection menu, choose Assign Macro (refer to Figure 3.10). In the dialog box that appears, select the macro you want to assign and click OK.

  • + Share This
  • 🔖 Save To Your Account