M
moishy
I've posted a question on http://tinyurl.com/6mflczk but it ha
seemingly come to a dead end (i.e. no response).
Here's the issue I'm dealing with, page layout in multi-colum
documents, since Word is not a desktop publishing solution, it doesn'
have a built-in option to align all columns equally at the bottom, an
therefore I have to do it manually. I'm using a function to find th
difference in points between two columns, the trouble is it doesn'
always work, sometimes it will return a value of several hundred point
when there hardly is a difference at all.
I'm posting the function here; I would appreciate any help I can get i
solving the mystery, and or improve the function.
Please note:
a. Although I will appreciate any help including alternative
suggestions, I would prefer if I can get some help with the function I'
currently using.
b. The function must work on a right-to-left forma
document.
c. Speed is a very important factor, as I plan to us
the function to display the difference in a text box on a user form tha
will get updated every time a change is made to one of the columns.
Code
-------------------
Function ColumnDiff()
Dim i As Integer, iCounter As Integer, iPos As Long, iPosCol As Long
Dim iCol() As Currency, nCol As Integer
Dim myRange As Range, iViewType As Integer, bEnd As Boolean
Const MaxDiff = 0 ' difference (in points) for the function to ignore
If Selection.StoryType 1 Then MsgBox "Cursor not in main text!": Exit Function
Set myRange = Selection.Range
Application.ScreenUpdating = False
iViewType = ActiveWindow.View.Type: ActiveWindow.View.Type = wdPrintView
iPos = -1
With Selection
.Collapse wdCollapseEnd
iCounter = iCounter + 1: StatusBar = iCounter
While iPos .Start
X2: iPos = .Start
If Dialogs(wdDialogFormatColumns).Columns = 1 Then GoTo X0
ReDim iCol(Dialogs(wdDialogFormatColumns).Columns + 1)
iPosCol = iPos: iPos = iPos - 1: nCol = 0
While iPos .Start
iPos = .Start
If Dialogs(wdDialogFormatColumns).Columns = 1 _
Or Dialogs(wdDialogFormatColumns).ColumnNo nCol _
Then GoTo X1
nCol = Dialogs(wdDialogFormatColumns).ColumnNo
iCol(nCol) = .Information(wdVerticalPositionRelativeToPage)
.GoToNext wdGoToLine
iCounter = iCounter + 1: StatusBar = iCounter
Wend
bEnd = True: iPos = ActiveDocument.StoryRanges(1).End
X1: For i = 1 To nCol ' iCol(0) = high peak
If iCol(0) iCol(i) Then iCol(0) = iCol(i)
Next i
iCol(nCol + 1) = iCol(0) ' iCol(nCol + 1) = low peak
For i = 1 To nCol
If iCol(nCol + 1) iCol(i) Then iCol(nCol + 1) = iCol(i)
Next i
If iCol(0) - iCol(nCol + 1) MaxDiff Then
.SetRange iPosCol, iPos
Application.ScreenUpdating = True
ColumnDiff = CCur(iCol(0) - iCol(i)) ' & "pt"
Exit Function
End If
If bEnd Then GoTo X3 Else GoTo X2
X0: .GoToNext wdGoToLine
iCounter = iCounter + 1: StatusBar = iCounter
Wend
End With
X3: myRange.Select
Application.ScreenUpdating = True: ActiveWindow.View.Type = iViewType
MsgBox "Done!"
End Function
-------------------
LIMITATIONS OF THE FUNCTION (NOT PROBLEMS!)
1. The function will only find the difference in the main text and no
in footnotes etc.
2. The function starts searching from the cursor location (or the end o
the selected text) till the end of the document.
RELATED QUESTION
http://tinyurl.com/7ju2puy
At the above url Macropad MVP has suggested several alternatives, a
mentioned there either the macro was too slow or I was not able to ge
it to work in right-to-left format
seemingly come to a dead end (i.e. no response).
Here's the issue I'm dealing with, page layout in multi-colum
documents, since Word is not a desktop publishing solution, it doesn'
have a built-in option to align all columns equally at the bottom, an
therefore I have to do it manually. I'm using a function to find th
difference in points between two columns, the trouble is it doesn'
always work, sometimes it will return a value of several hundred point
when there hardly is a difference at all.
I'm posting the function here; I would appreciate any help I can get i
solving the mystery, and or improve the function.
Please note:
a. Although I will appreciate any help including alternative
suggestions, I would prefer if I can get some help with the function I'
currently using.
b. The function must work on a right-to-left forma
document.
c. Speed is a very important factor, as I plan to us
the function to display the difference in a text box on a user form tha
will get updated every time a change is made to one of the columns.
Code
-------------------
Function ColumnDiff()
Dim i As Integer, iCounter As Integer, iPos As Long, iPosCol As Long
Dim iCol() As Currency, nCol As Integer
Dim myRange As Range, iViewType As Integer, bEnd As Boolean
Const MaxDiff = 0 ' difference (in points) for the function to ignore
If Selection.StoryType 1 Then MsgBox "Cursor not in main text!": Exit Function
Set myRange = Selection.Range
Application.ScreenUpdating = False
iViewType = ActiveWindow.View.Type: ActiveWindow.View.Type = wdPrintView
iPos = -1
With Selection
.Collapse wdCollapseEnd
iCounter = iCounter + 1: StatusBar = iCounter
While iPos .Start
X2: iPos = .Start
If Dialogs(wdDialogFormatColumns).Columns = 1 Then GoTo X0
ReDim iCol(Dialogs(wdDialogFormatColumns).Columns + 1)
iPosCol = iPos: iPos = iPos - 1: nCol = 0
While iPos .Start
iPos = .Start
If Dialogs(wdDialogFormatColumns).Columns = 1 _
Or Dialogs(wdDialogFormatColumns).ColumnNo nCol _
Then GoTo X1
nCol = Dialogs(wdDialogFormatColumns).ColumnNo
iCol(nCol) = .Information(wdVerticalPositionRelativeToPage)
.GoToNext wdGoToLine
iCounter = iCounter + 1: StatusBar = iCounter
Wend
bEnd = True: iPos = ActiveDocument.StoryRanges(1).End
X1: For i = 1 To nCol ' iCol(0) = high peak
If iCol(0) iCol(i) Then iCol(0) = iCol(i)
Next i
iCol(nCol + 1) = iCol(0) ' iCol(nCol + 1) = low peak
For i = 1 To nCol
If iCol(nCol + 1) iCol(i) Then iCol(nCol + 1) = iCol(i)
Next i
If iCol(0) - iCol(nCol + 1) MaxDiff Then
.SetRange iPosCol, iPos
Application.ScreenUpdating = True
ColumnDiff = CCur(iCol(0) - iCol(i)) ' & "pt"
Exit Function
End If
If bEnd Then GoTo X3 Else GoTo X2
X0: .GoToNext wdGoToLine
iCounter = iCounter + 1: StatusBar = iCounter
Wend
End With
X3: myRange.Select
Application.ScreenUpdating = True: ActiveWindow.View.Type = iViewType
MsgBox "Done!"
End Function
-------------------
LIMITATIONS OF THE FUNCTION (NOT PROBLEMS!)
1. The function will only find the difference in the main text and no
in footnotes etc.
2. The function starts searching from the cursor location (or the end o
the selected text) till the end of the document.
RELATED QUESTION
http://tinyurl.com/7ju2puy
At the above url Macropad MVP has suggested several alternatives, a
mentioned there either the macro was too slow or I was not able to ge
it to work in right-to-left format