View Single Post
 
Old 07-18-2019, 10:40 AM
sts023 sts023 is offline Windows 7 64bit Office 2010
Hopeless Idiot
 
Join Date: Apr 2019
Location: God's Own County
Posts: 26
sts023 is on a distinguished road
Default Now it hangs/loops!

Looks like I spoke too soon.

When processing with frequent "Stop" commands to check all is working, my code runs perfectly.

However, when running end-to-end it loops/freezes (i.e. it becomes unresponsive and I have to use Task Manager to dismis Word).

I've had similar issues with Excel in the past, where some functions need the VBA to be paused to allow the system to catch up. Is this a known issue with Range.Information?

(Note: My personal variable naming convention means that
any variable starting with "g" is declared globally in a separate "Globals" module)

In my document formatting I use the following code, which recovers the horizontal end points for each column:-
Code:
Public Sub SetColsInWholeDoc(intCols As Integer)
'#######################################
'# Set the required number of columns. #
'# N.B. The numcolumns parameter seems #
'#      to be the EXTRA columns (above #
'#      the basic 1), so we subtract   #
'#      1 from the User's specified    #
'#      column count.                  #
'#######################################
'*
'** Check it's a valid request.
'*
  If intCols < 2 Then Exit Sub
'*
'** Now set the required column count.
'*
  With Selection.Sections(1)
    With .PageSetup.TextColumns
      .SetCount NumColumns:=intCols - 1
      .Add Spacing:=InchesToPoints(0.25), _
                    EvenlySpaced:=True
    End With
    glngColWidth = .PageSetup.TextColumns(1).width
    gsngColWInches = PointsToInches(glngColWidth)
'    MsgBox glngColWidth & " pts, " & gsngColWInches & " inches"
  End With
'*
'** Set up horizontal end point of
'** of each page column.
'*
  glngCol1HEnd = glngColWidth
  Select Case intCols
    Case 1
      glngCol2HEnd = 0
      glngCol3HEnd = 0
    Case 2
      glngCol2HEnd = glngColWidth * 2
      glngCol3HEnd = 0
    Case 3
      glngCol2HEnd = glngColWidth * 2
      glngCol3HEnd = glngColWidth * 3
  End Select
End Sub 'SetColsInWholeDocc
then in order to determine the current column I "collapse to end" the range "rng" and call the function funGetCurPageCol as follows:-
Code:
Public Function funGetCurPageCol(rng As Range) As Long
Dim lngH                        As Long
  lngH = rng.Information(wdHorizontalPositionRelativeToPage)
  Select Case True
    Case lngH <= glngCol1HEnd
      funGetCurPageCol = 1
    Case lngH > glngCol1HEnd And _
         lngH <= glngCol2HEnd
      funGetCurPageCol = 2
    Case lngH > glngCol2HEnd
      funGetCurPageCol = 3
  End Select
End Function 'funGetCurPageCol
Any ideas? It's weird that it works on "step through" but not at normal pace...
Reply With Quote