Solved

OnPageClose Event in Frontpage 2003 - Creating an Add-In

Posted on 2004-09-15
16
252 Views
Last Modified: 2013-12-24
I'm trying to create an add-in in VB6 to use with Frontpage 2003.

I can create the definitions required to grab the event handling:

(e.g.
Dim WithEvents MyButton As Office.CommandBarButton
Dim WithEvents objAppEvents As FrontPage.Application
Dim WithEvents objWebEvents As FrontPage.WebEx
Dim WithEvents objWebWindowEvents As FrontPage.WebWindowEx
Dim WithEvents objPageWindowEvents As FrontPage.PageWindowEx
)

but none of the events actually fire!

Can anyone help or direct me to resources about either macros or add-ins that will work to capture events in FP2003.
0
Comment
Question by:ollertonk
  • 6
  • 3
  • 2
  • +1
16 Comments
 
LVL 12

Accepted Solution

by:
rcmb earned 300 total points
Comment Utility
Browse thru this - I gathered this from MSDN.

Working with Events

Events allow you to capture information when users perform certain tasks in Microsoft FrontPage. For example, when a user closes a Web site, you may want to publish the site. Responding to these events allows you to create custom applications that are intuitive. Using the Microsoft FrontPage Object Models, you can respond to events that are created by the FrontPage application (using the Application object model), a Web site (using the Web object model), or a page (using the Page object model). (For more information on the FrontPage Object Models, see About the FrontPage 2002 Object Models in this Software Development Kit.)

Declaring and Initializing Event Handler Variables

When you work with events, you must declare then with the WithEvents keyword inside a Class module. To do this:

Start FrontPage.
Press Alt+F11 to start the Microsoft Visual Basic Editor.
On the Insert menu, click Class Module to create a new class module.
Declare your event variables. These are global variables that you place at the top of your class module.

Private WithEvents objAppEvents as FrontPage.Appliction
Private WithEvents objWebEvents As FrontPage.WebEx
Private WithEvents objWebWindowEvents As FrontPage.WebWindowEx
Private WithEvents objPageWindowEvents As FrontPage.PageWindowEx
Private WithEvents objAnchorEvent As FPHTMLAnchorElement

Once you declare the variables, you will be able to access the list of events in the Procedure list. To do so, select the object that you want to work with in the Object list.
Lastly, you need to add a class initialize event routine. Do do this, click class in the Object list and click Initialize in the Procedure list.  Then enter the code to set the event handler variable equal to the object, as shown below.

Private Sub Class_Initialize()
    Set objAppEvents = FrontPage.Application
End Sub
You also need to initialize your class module from a general code module. If in the above procedure, you created a new class module and accepted all the defaults, you would have a class module called Class1. To initialize this class module, do the following:

Create a general code by clicking Module on the Insert menu.
Create a global variable to handle the new class.
Dim cls As Class1
Write an initialization subroutine.

Sub InitializeClass1()
    Set cls = New Class1
End Sub
Run the initialization subroutine by positioning the cursor inside it and pressing F5. If you step through it by pressing F8, you will notice that when the cls class variable initializes, it runs the Initialize event routine in the Class1 code module.
Working with the Application Object Model Events
There are a variety of application events for which you can create code to handle. First, you must declare and initialize the event handler, as shown above.  Next, you need to access the event for which you want to write code. To do this,

Select the event handler variable in the Objects list.

Click on the event for which to create code in the Procedures list.
For example, if you wanted to run code every time the active document closed, you would select the OnPageClose event. The following sample uses the OnPageClose event to display a message to determine if the user really wanted to close the active page window. If the user clicks No, the page close event is canceled.

Private Sub objAppEvents_OnPageClose(ByVal pPage As PageWindow, _
        Cancel As Boolean)

    If (MsgBox("You are closing the active page. " & _
            "Are you sure you want to do that?", _
            vbYesNo, "Close page?") = vbNo) Then
        Cancel = True
    End If

End Sub
Working with the Web Object Model Events
You can create two types of events handlers for Web sites. One deals with general Web events and the other deals with Web window events.

Web Events

Some of the events included in Web events are OnBeforePublish, OnAfterPublish, and OnClose. These events deal with the entire Web and not just the items in the Web window, which the Web window events handle.

To illustrate, let's say you want to write special code to handle when a user closes a Web site. You would use the OnClose event. The following example displays a message to determine if the user really wants to close the current Web site. If the user clicks No, the event is canceled.

Private Sub objWebEvents_OnClose(pCancel As Boolean)

    If (MsgBox("You have chosen to close the current " & _
            "Web. Are you sure you want to do that?", _
            vbYesNo, "Close page?") = vbNo) Then
        pCancel = True
    End If

End Sub

Web Window Events

Web window events handle events related to the FrontPage Web window, such as the current view. The OnBeforeViewChange and OnAfterViewChange events handle processes for when a user switches from one view to another. The following example displays a message when a user switches view to determine if a user really wants to switch to the new view. If the user clicks No, the event is cancelled.

Private Sub objWebWindowEvents_OnBeforeViewChange(ByVal _
        TargetView As FpWebViewModeEx, Cancel As Boolean)

    If (MsgBox("You have chosen to close switch the current " & _
            "view. Are you sure you want to do that?", _
            vbYesNo, "Close page?") = vbNo) Then
        Cancel = True
    End If

End Sub

Note   This is Web views not page views, which are handled by page window events. Instead the OnBeforeViewChange Web event fires when you switch from Page view to Reports view.

Page Window Events

Page window events handle events that relate to the page view; for example, when a page window is closed, saved, or the page view is changed. The following example displays a message when a user switches view to determine if a user really wants to switch to the new view. If the user clicks No, the event is cancelled.

Private Sub objPageWindowEvents_OnBeforeViewChange(ByVal _
        TargetView As FpPageViewMode, Cancel As Boolean)

    If (MsgBox("You have chosen to switch the current " & _
            "view. Are you sure you want to do that?", _
            vbYesNo, "Close page?") = vbNo) Then
        Cancel = True
    End If

End Sub

Working with Page Object Model Events

There are a variety of events for which you can create event handlers using the Page Object Model. For example, many of the HTML elements on a page allow for click and mouseover events. You can use the Page Object Model to handle these events at design time.

Note   For run-time event handling, you should use scripting inside your page.

The following example displays a message when a user clicks on the first hyperlink in the Preview page window.

Private Function objAnchorEvent_onclick() As Boolean

    MsgBox "Hello, " & Application.UserName & ". You have " & _
        "just clicked a hyperlink. Click OK to continue."

End Function

To fire the above event, you must create an event handler class and initialize it (as shown above) so that when you click on a hyperlink in the FrontPage Preview window, it fires the onclick event and you receive the message.
0
 
LVL 1

Author Comment

by:ollertonk
Comment Utility
Thanks rcmb,

I came across the same article on MSDN.  If you enter these as directed nothing happens regardless of which event you fire. (I added msgboxes to each event and nothing worked).

Any further suggestions gratefully received!
0
 
LVL 19

Expert Comment

by:webwoman
Comment Utility
You don't use VB, you use javascript. VB won't interact with the browser, javascript will.
0
 
LVL 1

Author Comment

by:ollertonk
Comment Utility
Sorry webwoman but I'm actually trying to interact with FrontPage (not the browser) through either a macro or a COM-AddIn
0
 
LVL 19

Expert Comment

by:webwoman
Comment Utility
Then you should request this be moved to the VB section -- you're not too likely to find VB programmers in the FP area.
0
 
LVL 1

Author Comment

by:ollertonk
Comment Utility
I'd imagined thought that macro creation would be used by Frontpage users
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 14

Expert Comment

by:hhammash
Comment Utility
Yes,  you are right here,  FrontPage users can create macros using VBA.  You imagined right.

hhammash
0
 
LVL 14

Expert Comment

by:hhammash
Comment Utility
VB is Visual Basic
VBA is Visual Basic for Applications

VBA a slightly different because it has certain  functions and commands that relate to office applications.


hhammash
0
 
LVL 14

Expert Comment

by:hhammash
Comment Utility
Frontpage macros help you accomplish tasks in Frontpage while designing the website,  but they do not affect the website when it is published.
0
 
LVL 14

Expert Comment

by:hhammash
Comment Utility
In my opinion,  I think that rcmb offered him something here.
0
 
LVL 14

Expert Comment

by:hhammash
Comment Utility
I know that the quesiton has been abandoned by the asker, but I'll add this link which might help others when they search for add-ins.

Here in Jimco there are some free add-ins for download.

http://www.jimcoaddins.com/addins.aspx

hh
0
 
LVL 12

Expert Comment

by:rcmb
Comment Utility
I believe my answer was correct and probably used by the asker.

RCMB
0
 
LVL 14

Expert Comment

by:hhammash
Comment Utility
No objection rcmb gave a good reply
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now