Re: Catching the New Page event in VBA

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks, Tony, for your prompt reply. As you say, it is wise to avoid Windows
API calls, as it gets complicated. In answer to your question, when a user
creates a new document based on this template, a dialog box opens
automatically and the user types in the address and all other info using
textboxes and combo boxes. The reference number and the subject of the letter
are also entered here (and stored in global string variables). The OK button
then inserts the data (with all required paragraph formatting, font selection
etc.) such that the user can immediately start typing the body of the letter.
The address is positioned on the page so that it fits in the envelope window,
and all the other details (date, senders address, signature etc.) are
automatically positioned on the page.

If the letter is long, and the user types into a second (or even a third)
page then, at the moment the new page is created, the reference code and
subject of the letter must be inserted into the new page header, using the
previously stored data (I use ranges and frames for this part). Life would be
SO much easier if a New Page event existed ! Thanks again, Tony for your help
:)
--
Lars


"Tony Jollans" wrote:

The Window Selection_Change event is the closest you will get (without using
heaps of APIs) - and it has some side effects in the UI, but ...

What is it you want to do when a new page is started?

--
Enjoy,
Tony

"Lars" <Lars@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:34EA4365-1F35-4EAD-8376-7F3914361D21@xxxxxxxxxxxxxxxx
I am developing an MS Word (xp) template for a corporate letterhead that
will
automatically insert the reference number (already stored in a variable
from
the first page) into the header of the second (and subsequent) pages.

I am aware that there is no "new page" event in Word that can be caught.

The solution I am working on involves checking the
'ActiveDocument.BuiltInDocumentProperties("number of pages")' property and
running the code as soon as the page number has incremented.
Unfortunately, I
cannot find a way of checking this value each time the user types a new
character.

Here is the code I am using at this time :

Option Explicit
Private WithEvents wdApp As Word.Application
Dim page1 As Integer
Dim page2 As Integer

'This line is executed during the loading of the document
page1 = ActiveDocument.BuiltInDocumentProperties("number of pages")


Private Sub wdApp_WindowSelectionChange(ByVal Sel As Selection)
page2 = ActiveDocument.BuiltInDocumentProperties("number of pages")
If page2 > page1 Then
MsgBox "Now on page " & Format(page2)
'Do the necessary operation here...
.
.
.
End If
End Sub

Unfortunately, the above sub is only works when I click with the mouse
anywhere in the document.

I tried other subs from the same set and I thought that
'wdApp_DocumentChange()' would be the one to use, but this dosen't work
either.

Can anyone give me a pointer as to how I can trap the 'new character
event'
(if there is one) and to check if the page number has changed ?

Any help will be greatly appreciated !

Many thanks,
--
Lars


.



Relevant Pages

  • Re: Catching the New Page event in VBA
    ... Thanks, Tony for your reply. ... and the user types into a second ... Dim page2 As Integer ... Private Sub wdApp_WindowSelectionChange ...
    (microsoft.public.word.vba.general)
  • Re: Close form?
    ... "Tony Williams" wrote in message ... >> Private Sub txtMontha_Exit ... >> Dim TitleStr As String ...
    (microsoft.public.access.formscoding)
  • Re: Toggle macro button
    ... Sub ToggleState(myControl As CommandBarControl, myState As String, Optional ... Dim SavedState As Boolean ... Tony ... >>> Dim OldState As Boolean ...
    (microsoft.public.word.vba.beginners)
  • Re: Once again... (getting frustrated with .NET) Winsock or TCPListener?
    ... On Wed, 02 Jun 2004 04:37:02 GMT, Tony wrote: ... > sent to the Windows App every 0.5 seconds over raw sockets. ... End Sub ... Private Sub ConnectionRequested ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Combobox needs to update table
    ... > If the user types a name that is not ... Private Sub Form_Load ... On Error GoTo ErrHandler ... Exit Sub ...
    (microsoft.public.access.forms)