Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.



Public Function lngForcePage(strDoc As String, strFlag As String, intMod As Integer, lngBreakType As Long) As Long
' Procedure :  lngForcePage
' Description: Forces section breaks to odd pages where the flag strcRHPage is found.
' Copyright: Chris Greaves
' Inputs:      A document name, a flag, a break type (wdSectionOddPage to force right-hand pages).
' Action:      None.
' Returns:
' Assumes:     The document is open.
' Side Effects:Repagination will take place at some stage, TOC entries, TOI etc.
' Tested:      By the calls shown below.
   Call Trace("lngForcePage")
   Dim boolSet As Boolean
   boolSet = boolUnHide ' save the setting, then unhide the text
   Dim lngCount As Long
   lngCount = 0
   Selection.HomeKey Unit:=wdStory
   ' Where we find the flag, we force a section break if required.
   Selection.Find.ClearFormatting
     'Selection.Find.Font.Hidden = True
  With Selection.Find
      .Text = strFlag
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindContinue
      .Format = True
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Dim lngPageNum As Long
   While Selection.Find.Execute
' wdActiveEndAdjustedPageNumber   Returns the number of the page that contains the active end of the specified selection or range. If you set a starting page number or make other manual adjustments, returns the adjusted page number (unlike wdActiveEndPageNumber).
' wdActiveEndPageNumber   Returns the number of the page that contains the active end of the specified selection or range, counting from the beginning of the document. Any manual adjustments to page numbering are disregarded (unlike wdActiveEndAdjustedPageNumber).
      lngPageNum = Selection.Information(wdActiveEndPageNumber)
Call Trace("found tag at " & str(lngPageNum))
      If lngPageNum Mod 2 = intMod Then  ' it is an page to be adjusted so
         lngCount = lngCount + 1
         'if we want the found text deleted, do it here
         ' selection.delete
         Selection.Collapse Direction:=wdCollapseStart
         Dim lngMovement As Long
         lngMovement = lngBackUpToNonHiddenText
         If Selection.Text = Chr(12) Then ' we are at a section break
'            Selection.MoveLeft Unit:=wdCharacter, Count:=1
         End If
         Selection.InsertBreak (lngBreakType)
         Selection.MoveRight Unit:=wdCharacter, Count:=lngMovement + 2 ' 99/09/09
      lngPageNum = Selection.Information(wdActiveEndPageNumber)
Call Trace("made RHPage am now at " & str(lngPageNum))
      Else
      End If
   Wend
   lngForcePage = lngCount
   Call boolUnHideRestore(boolSet) ' restore the setting
' Sub TESTlngForcePage()
'MsgBox lngForcePage(ActiveDocument.Name, "ODD PAGE", 0, wdPageBreak)
'End Sub
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1

Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.

Public Function lngForcePage(strDoc As String, strFlag As String, intMod As Integer, lngBreakType As Long) As Long
' Procedure :  lngForcePage
' Description: Forces section breaks to odd pages where the flag strcRHPage is found.
' Copyright: Chris Greaves
' Inputs:      A document name, a flag, a break type (wdSectionOddPage to force right-hand pages).
' Action:      None.
' Returns:
' Assumes:     The document is open.
' Side Effects:Repagination will take place at some stage, TOC entries, TOI etc.
' Tested:      By the calls shown below.
   Call Trace("lngForcePage")
   Dim boolSet As Boolean
   boolSet = boolUnHide ' save the setting, then unhide the text
   Dim lngCount As Long
   lngCount = 0
   Selection.HomeKey Unit:=wdStory
   ' Where we find the flag, we force a section break if required.
   Selection.Find.ClearFormatting
     'Selection.Find.Font.Hidden = True
  With Selection.Find
      .Text = strFlag
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindContinue
      .Format = True
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Dim lngPageNum As Long
   While Selection.Find.Execute
' wdActiveEndAdjustedPageNumber   Returns the number of the page that contains the active end of the specified selection or range. If you set a starting page number or make other manual adjustments, returns the adjusted page number (unlike wdActiveEndPageNumber).
' wdActiveEndPageNumber   Returns the number of the page that contains the active end of the specified selection or range, counting from the beginning of the document. Any manual adjustments to page numbering are disregarded (unlike wdActiveEndAdjustedPageNumber).
      lngPageNum = Selection.Information(wdActiveEndPageNumber)
Call Trace("found tag at " & str(lngPageNum))
      If lngPageNum Mod 2 = intMod Then  ' it is an page to be adjusted so
         lngCount = lngCount + 1
         'if we want the found text deleted, do it here
         ' selection.delete
         Selection.Collapse Direction:=wdCollapseStart
         Dim lngMovement As Long
         lngMovement = lngBackUpToNonHiddenText
         If Selection.Text = Chr(12) Then ' we are at a section break
'            Selection.MoveLeft Unit:=wdCharacter, Count:=1
         End If
         Selection.InsertBreak (lngBreakType)
         Selection.MoveRight Unit:=wdCharacter, Count:=lngMovement + 2 ' 99/09/09
      lngPageNum = Selection.Information(wdActiveEndPageNumber)
Call Trace("made RHPage am now at " & str(lngPageNum))
      Else
      End If
   Wend
   lngForcePage = lngCount
   Call boolUnHideRestore(boolSet) ' restore the setting
' Sub TESTlngForcePage()
'MsgBox lngForcePage(ActiveDocument.Name, "ODD PAGE", 0, wdPageBreak)
'End Sub
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1