Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 07-18-2019, 10:40 AM
sts023 sts023 is offline Identify current column on a page Windows 7 64bit Identify current column on a page Office 2010
Hopeless Idiot
Identify current column on a page
 
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
 

Tags
columns, count, information



Similar Threads
Thread Thread Starter Forum Replies Last Post
Identify current column on a page Return nameof Left column in current view trevorc Excel Programming 7 09-19-2018 08:38 PM
Identify current column on a page Table adding cells to previous page with room still on current page. gedet Word 1 01-03-2018 10:35 AM
Identify last blank cell in column mbesspiata Excel 0 02-27-2015 11:29 AM
How to save the current page in a new file with all the page settings (header, footer Jamal NUMAN Word 6 03-15-2012 03:27 PM
Is there a way to automatically highlight the column and the row that of the current Jamal NUMAN Excel 8 02-14-2012 02:58 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:12 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft