View Single Post
 
Old 07-29-2025, 04:59 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Paul,


Thanks. Poor description of the problem on my end. I realized that it was the repositioning steps that were failing. What I was looking for is some understanding of why if fails?


Why it fails if 1) starting with the selection in the first page content and not if in the odd page content and 2) why if fails when running the code and not if stepping through.


Code:
Private Sub DemoIssue()
Dim oRngStart As Range
Dim lngIndex As Long, lngSect
  Application.ScreenUpdating = False
  For Each oSec In ActiveDocument.Sections
    For lngIndex = 1 To 3
      Set oRng = oSec.Headers(lngIndex).Range
      For Each oShp In oRng.ShapeRange
        If InStr(oShp.Name, "PrivBox_") = 1 Then oShp.Delete
      Next
    Next lngIndex
  Next oSec
  For Each oSec In ActiveDocument.Sections
    For lngIndex = 1 To 3
      If Not oSec.Headers(wdHeaderFooterPrimary).LinkToPrevious Then
        InsertBox lngIndex
        If lngIndex = 1 Then Set oShpDup = oShp
        'DoEvents
      End If
    Next lngIndex
  Next oSec
  'But why does it fail? Using the origianal position 337.05, 72.2, 207#, 27# in the InsertBox procedure
  'Run the code with this Stop
  'Stop
  'Then step through and the Odd page is positioned correctly.
  'Remove the stop ans run the code.
  With oShpDup
    Debug.Print .Left & " - " & .Top
    .RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn
    .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
    .Left = InchesToPoints(3.68)
    .Top = InchesToPoints(0)
    Debug.Print .Left & " - " & .Top
  End With
  Application.ScreenUpdating = True
  Application.ScreenRefresh
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote