Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

OnPageClose Event in Frontpage 2003 - Creating an Add-In

Posted on 2004-09-15
16
Medium Priority
?
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +1
16 Comments
 
LVL 12

Accepted Solution

by:
rcmb earned 1200 total points
ID: 12069664
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
ID: 12100145
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
ID: 12106159
You don't use VB, you use javascript. VB won't interact with the browser, javascript will.
0
Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

 
LVL 1

Author Comment

by:ollertonk
ID: 12122217
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
ID: 12129521
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
ID: 12345669
I'd imagined thought that macro creation would be used by Frontpage users
0
 
LVL 14

Expert Comment

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

hhammash
0
 
LVL 14

Expert Comment

by:hhammash
ID: 12457853
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
ID: 12457864
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
ID: 12671511
In my opinion,  I think that rcmb offered him something here.
0
 
LVL 14

Expert Comment

by:hhammash
ID: 12671527
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
ID: 12671729
I believe my answer was correct and probably used by the asker.

RCMB
0
 
LVL 14

Expert Comment

by:hhammash
ID: 12830419
No objection rcmb gave a good reply
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

609 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