How to run a piece of code when a page is opened for editing ?

J

Jon

We use Frontpage as an editor for our help-projects, and I
need to run a function when any of the documents in the
WEB is opened.

Does anyone know how to do this ?

Jon
 
S

Stefan B Rusynko

If you are trying to run the function from the web (browser) interface you can't (security won't allow .exe to run and VBA is
unsupported) unless you are using a HTA
See http://www.microsoft.com/office/com....frontpage.extensions.windowsnt&lang=en&cr=US

If you are trying to run it in FP, recommend you create your VBA and a custom button to invoke your code to open Sourcesafe, rather
than relying on trying to capture the File Open event (too many ways to open pages)




| A VBA-function that runs Shell(SS.EXE)to check out the
| file from Sourcesafe.
|
| Jon
|
| >-----Original Message-----
| >What type of function.
| >
| >
| >--
| >95isalive
| >This site is best viewed..................
| >...............................with a computer
| >| >> We use Frontpage as an editor for our help-projects,
| and I
| >> need to run a function when any of the documents in the
| >> WEB is opened.
| >>
| >> Does anyone know how to do this ?
| >>
| >> Jon
| >
| >
| >.
| >
 
J

Jim Cheshire

Hook the OnPageOpen event for the Application object. For example:

Dim WithEvents fpApp As FrontPage.Application

Now you will be able to select "fpApp" in the left dropdown in code view and
then select "OnPageOpen" in the right dropdown. Add your code to that event
and it will fire each time a page is opened.

--
Jim Cheshire
Jimco Add-ins
http://www.jimcoaddins.com
===================================
Co-author of Special Edition
Using Microsoft FrontPage 2003
Order it today!
http://sefp2003.frontpagelink.com
 
J

Jon

Thanks for the reply. When is the code called ? I made a
class module in the VBA-part of FP, and inserted this
code :

Dim WithEvents fpApp As FrontPage.Application
Private Sub fpApp_OnPageOpen(ByVal pPage As PageWindow)
MsgBox "You are in fpApp_OnPageOpen !"
End Sub

Nothing happens when a file is opened in the web, but I
would think I am missing something....

Jon
 
J

Jim Cheshire

Jon,

In your class module, you would do the following:
--------------------
Dim WithEvents fpApp As FrontPage.Application

Private Sub Class_Initialize()
Set fpApp = FrontPage.Application
End Sub

Private Sub fpApp_OnPageOpen(ByVal pPage As PageWindow)
MsgBox pPage.ActiveDocument.Url
End Sub
--------------------

What you have here is a class-level variable (fpApp) that contains a
reference to the FrontPage application. You then have the code in
Class_Initialize (which runs when a new instance of the class is created)
that simply sets the fpApp variable equal to the current instance of
FrontPage. Next you have the code that represents the OnPageOpen event. In
this case, I just display the URL of the document.

Now you need a user module that you will call from the Macros dialog. This
user module will simply instantiate a new instance of your class. Before I
do that, I rename my class from Class1 (the default) to something more
informative to me. In this case, I renamed it PageOpenMessage.

Here is the code in my user module:
-------------------------------
Dim poMsg As PageOpenMessage
Public Sub hookEvents()
Set poMsg = New PageOpenMessage
End Sub
-------------------------------

This code defines a variable (poMsg) that will contain an instance of my
PageOpenMessage class. It is defined at the module level outside of any sub
procedures so that it will work for the life of my app. The hookEvents sub
procedure is the procedure that shows up in the macros dialog, and it is the
macro that you will run. When you run it, it simply creates a new instance
of PageOpenMessage, and that instance is assigned to the poMsg variable.

That's all there is to it. Open Tools, Macros, Macro and run the hookEvents
macro to get going.

--
Jim Cheshire
Jimco Add-ins
http://www.jimcoaddins.com
===================================
Co-author of Special Edition
Using Microsoft FrontPage 2003
===================================
Our newest add-in:
FrontPage Cart Companion
http://www.frontpagecartcompanion.com
 
J

Jon Hagen

Thanks, it worked ! Great !

Jon Hagen
-----Original Message-----
Jon,

In your class module, you would do the following:
--------------------
Dim WithEvents fpApp As FrontPage.Application

Private Sub Class_Initialize()
Set fpApp = FrontPage.Application
End Sub

Private Sub fpApp_OnPageOpen(ByVal pPage As PageWindow)
MsgBox pPage.ActiveDocument.Url
End Sub
--------------------

What you have here is a class-level variable (fpApp) that contains a
reference to the FrontPage application. You then have the code in
Class_Initialize (which runs when a new instance of the class is created)
that simply sets the fpApp variable equal to the current instance of
FrontPage. Next you have the code that represents the OnPageOpen event. In
this case, I just display the URL of the document.

Now you need a user module that you will call from the Macros dialog. This
user module will simply instantiate a new instance of your class. Before I
do that, I rename my class from Class1 (the default) to something more
informative to me. In this case, I renamed it PageOpenMessage.

Here is the code in my user module:
-------------------------------
Dim poMsg As PageOpenMessage
Public Sub hookEvents()
Set poMsg = New PageOpenMessage
End Sub
-------------------------------

This code defines a variable (poMsg) that will contain an instance of my
PageOpenMessage class. It is defined at the module level outside of any sub
procedures so that it will work for the life of my app. The hookEvents sub
procedure is the procedure that shows up in the macros dialog, and it is the
macro that you will run. When you run it, it simply creates a new instance
of PageOpenMessage, and that instance is assigned to the poMsg variable.

That's all there is to it. Open Tools, Macros, Macro and run the hookEvents
macro to get going.

--
Jim Cheshire
Jimco Add-ins
http://www.jimcoaddins.com
===================================
Co-author of Special Edition
Using Microsoft FrontPage 2003
===================================
Our newest add-in:
FrontPage Cart Companion
http://www.frontpagecartcompanion.com





.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top