Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2006

Tip: Looking for answers? Try searching our database.

Any way to have a messagebox pop up whenever a new page is started?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
xerj - 22 Apr 2006 12:18 GMT
Thanks in advance if anyone knows how to do it.
Jezebel - 22 Apr 2006 12:28 GMT
No way to do this. Word has no direct event trapping related to keypresses.

> Thanks in advance if anyone knows how to do it.
xerj - 22 Apr 2006 12:56 GMT
Damn.

That kind of ruins an elaborate plan I was working on.

Thanks for the info.

> No way to do this. Word has no direct event trapping related to
> keypresses.
>
>> Thanks in advance if anyone knows how to do it.
champollion.yves@wanadoo.fr - 28 Apr 2006 16:18 GMT
I do event trapping on keystrokes all the time.

I suppose you're programmers, so I'll only describe the principle at
work, with minimal code.

You associate a common key with a macro. For example, the spacebar. The
necessary code would be as follows:

 KeyBindings.Add 1, "MyKeyEventSpace", BuildKeyCode(wdKeySpacebar)

Every time the users presses the space bar, your MyKeyEventSpace macro
fires. Make sure the first thing the macro does is *actually* type the
space:

 Selection = " ": Selection.Collapse 0

Inside that macro, you have a persistent variable (by persistent, I
mean a document variable, not a VBA variable that dies at the first
End) that records the current page number. If that number is different
from the current page, you know you moved to a different page and you
can take action.

Now you may also link some navigation keys (KeyDown, PageDown) in the
same way to make sure the macro fires even when you just navigate
without typing.

Make sure the KeyBindings is disabled when not in use anymore.

Cheers,
Yves Champollion
www.champollion.net
Jean-Guy Marcil - 28 Apr 2006 17:39 GMT
champollion.yves@wanadoo.fr was telling us:
champollion.yves@wanadoo.fr nous racontait que :

> I do event trapping on keystrokes all the time.
>
[quoted text clipped - 21 lines]
> same way to make sure the macro fires even when you just navigate
> without typing.

So, to answer the original post, you would have to bind all possible keys.
including the SHIFT and ALT-CAR combinations)?
Lots of work, no?

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

champollion.yves@wanadoo.fr - 28 Apr 2006 20:28 GMT
> xerj writes:
> What I am after is a way to have Word automatically assess a paragraph that
goes over the end of the page and apply formatting as the user types.
It's a
little like widow/orphan control but there are some other added
wrinkles.

No need to bind all possible keys. IMHO, you don't need to run the test
[have we moved one page?] at *every* keystroke. Trapping the spacebar
is amply sufficient, unless xerj wants the Japanese/Chinese to use his
system - they make less use of spaces indeed.

AFAIU, xerj needs to notice when, in the course of typing, textflow
moves into a new page (do I get him right?). I would trap the Enter key
in addition to the Spacebar, but it's a matter of choice. The less keys
you trap the better. It's pretty unlikely someone would type and type
without spaces.

Cheers,
Yves Champollion
www.champollion.net
Jean-Guy Marcil - 28 Apr 2006 23:39 GMT
champollion.yves@wanadoo.fr was telling us:
champollion.yves@wanadoo.fr nous racontait que :

>> xerj writes:
>> What I am after is a way to have Word automatically assess a
[quoted text clipped - 14 lines]
> less keys you trap the better. It's pretty unlikely someone would
> type and type without spaces.

True enough. But in many cases the user would get the "new page" routine
after the new page is created (when typing long words that wrap to the next
line in mid-word).

But I guess it is a compromise that could satisfy the OP.

He could implement both our ideas and get pretty close to what he wants
without too much overhead.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

Jean-Guy Marcil - 22 Apr 2006 15:51 GMT
xerj was telling us:
xerj nous racontait que :

> Thanks in advance if anyone knows how to do it.

As Jezebel pointed out, you cannot really trap user keystrokes... but, you
can trap user selection changes. So, this might be useful.
Whenever the user clicks somewhere; selects something to delete, copy, paste
or to change paragraph/font attributes; inserts a table, etc., then the
following code will work and if the number of pages changes, you can be
informed:

Paste this in the ThisDocument module: (This bit will call the standard
module that must register the event handler every time the document is
opened or created from the template, if you are working from a template)

'_______________________________________

Private Sub Document_New()

WordEventModule.RegisterEH

PageCount = ActiveDocument.Range.Information(wdNumberOfPagesInDocument)

End Sub

'_______________________________________

'_______________________________________

Private Sub Document_Open()

WordEventModule.RegisterEH

PageCount = ActiveDocument.Range.Information(wdNumberOfPagesInDocument)

End Sub

'_______________________________________

In a class module that you MUST name "WordEventHandler", paste the following
code: (This is the code that actually does the work when the event is
triggered. You could have a call to a procedure in a standard module if you
prefer)

'_______________________________________

Public WithEvents WordApp As Word.Application

'_______________________________________

Private Sub WordApp_WindowSelectionChange(ByVal Sel As Selection)

Dim NewPageCount As Long

NewPageCount = ActiveDocument.Range.Information(wdNumberOfPagesInDocument)

If NewPageCount > PageCount Then

           MsgBox "The page count has increased"

           PageCount = NewPageCount

ElseIf NewPageCount < PageCount Then

           MsgBox "The page count has decreased"

           PageCount = NewPageCount

End If

End Sub'_______________________________________

Finally, in a standard module which you MUST name "WordEventModule", paste
this code: (This will register the event handler, or activate it if you
will)

'_______________________________________

Public MyWordEvent As New WordEventHandler

Public PageCount As Long

'_______________________________________

Public Sub RegisterEH()

           'Register the Event Handler

           Set MyWordEvent.WordApp = Word.Application

End Sub

'_______________________________________

For more on this application-triggered event, see:
   http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbawd11/html/wo
evtWindowSelectionChange_HV05277162.asp

(Watch out for URL wraping!)

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

xerj - 22 Apr 2006 22:52 GMT
Wow, thanks JG!

It's kind of frustrating that keystrokes can't be trapped, or there isn't an
inbuilt or way to build something like a "OnNewPageCreated" event. It must
be doing it initernally, so you'd think that when it fires you'd have
programattic access to it somehow.

But thanks for all that code!
Charles Kenyon - 23 Apr 2006 04:47 GMT
I don't know of any way to do this, but suspect that there is a way to
accomplish what you want with your message box. What is it you are trynig to
accomplish?
Signature

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!

My criminal defense site: http://addbalance.com
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

> Thanks in advance if anyone knows how to do it.
xerj - 28 Apr 2006 12:30 GMT
Hi Charles.

The message box idea was just to test something.

What I am after is a way to have Word automatically assess a paragraph that
goes over the end of the page and apply formatting as the user types. It's a
little like widow/orphan control but there are some other added wrinkles.

If you have any ideas I'd like to hear them!

>I don't know of any way to do this, but suspect that there is a way to
>accomplish what you want with your message box. What is it you are trynig
>to accomplish?
>> Thanks in advance if anyone knows how to do it.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.