PDA

View Full Version : Page Layout in multi-column documents



MacroShadow
03-26-2012, 03:06 AM
Hello all experts,


I'm dealing with is page layout in multi-column documents, since Word is not a desktop publishing solution, it doesn't have a built-in option to align all columns equally at the bottom, and therefore I have to do it manually (after inserting a continuous section break at the end of each page) by adjusting the following: 1. the line spacing 2. the spacing before and after paragraphs.


I'm using a function to find the difference in points between two columns, so I know how much of a change I must make.




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 and problems with this function:
1. It doesn't always work, sometimes it will return a value of several hundred points when there hardly is a difference at all between the columns.

2. The function will only find the difference in the main text and not in footnotes etc.
3. The function starts searching from the cursor location (or the end of the selected text) till the end of the document.
I would appreciate any help I can to improve the function.


p.s.
For anybody that will suggest an alternative, please note: 1. The function must work with columns in right-to-left format 2. The speed factor is very important 3. If there are more than two columns, the function should return the difference for each column.


p.p.s.
I have posted this question at http-social.msdn.microsoft.com/Forums/en-US/worddev/thread/34cdc003-fee8-45db-9b91-1d39f5219b33 where Macropad has been kind enough to suggest a sub to accomplish some of the above, I still need help with it and it has been some time since a reply was given. The point of this post is to get a fresh pair of eyes to look at this, and if Macropad sees it, to show I have not lost interest in solving the issue.
Also posted at http-w-ww.wordbanter.com/showthread.php?p=492128#post492128, but haven't received useful replies.

p.p.p.s.
I can't seem to insert the code formatted properly, I offer my most sincere apologies. I would appreciate if a moderator can correct the code format. btw, at the above forum the code is formatted properly.

fumei
03-26-2012, 01:06 PM
The reason the code is not formatted properly is that you do not have hard returns at the end of each line. Please make sure - if you get code from else where, that you check this. Just press Enter at the end of a proper line...AND if you are using mutliple lines, use the underscore character.

And...the code also uses those darn colons. Tecthnically it is legitimate syntax, but I hate the use of colons. Once or twice in a procedure, reluctantly...OK, but if it is used too much it makes for very unreadable code IMO.

I doubt the code is properly formatted. I know it isn't. That site is just more forgiving. Please, if you want to copy code from there, copy it first and put in hard returns before posting here.

MacroShadow
03-26-2012, 01:30 PM
I copied the code from my Word template, and there it seems to be formatted properly.

fumei
03-26-2012, 03:19 PM
Clearly it was not. Are there hard returns after, say..after ColumnDiff()?

Function ColumnDiff() Dim i As Integer, iCounter As Integer, iPos As Long, iPosCol As Long

It sure does seem so.

MacroShadow
03-26-2012, 03:56 PM
Wow, Sorry my mistake I copied the code from a website after posting it there, that must have messed things up, here is the function pasted directly from my Word template:

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

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

macropod
03-26-2012, 10:58 PM
This all looks to me suspiciously like a cross-post of:
http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/34cdc003-fee8-45db-9b91-1d39f5219b33/
http://www.wordbanter.com/showthread.php?t=155119
With no recognition of the effort that's already been put into addressing the issue, including the development of two fully-serviceable macros that can do the job in documents using a left-to-right layout.

If it is indeed the same issue, your omission of the fact that the troublesome document uses right-to-left layout potentially makes a huge difference.

MacroShadow
03-26-2012, 11:02 PM
Hello all experts,
p.p.s.
I have posted this question at http-social.msdn.microsoft.com/Forums/en-US/worddev/thread/34cdc003-fee8-45db-9b91-1d39f5219b33 where Macropad has been kind enough to suggest a sub to accomplish some of the above, I still need help with it and it has been some time since a reply was given. The point of this post is to get a fresh pair of eyes to look at this, and if Macropad sees it, to show I have not lost interest in solving the issue.
Also posted at http-w-ww.wordbanter.com/showthread.php?p=492128#post492128, but haven't received useful replies.

Macropad,

As you can see I did mention that I posted this else where.

macropod
03-26-2012, 11:09 PM
Sorry,

Missed that bit. All, the same though, you should have mentioned the fact that you already have two working macros - for documents using a left-to-right layout - one of which apparently works in document with a right-to-left layout, and all you're really after is something that's faster. Your initial post relies on your own inaccurate macro, not on something you've already been given that provides known good results.

MacroShadow
03-27-2012, 12:08 AM
I'm sorry, I guess I'm just a slow learner... Hopefully one of these days I'll get it right:(

MacroShadow
03-27-2012, 12:24 AM
Your initial post relies on your own inaccurate macro...

Macropad,

Did you call it inaccurate because it doesn't provide the desirable results, or is there some other flaw?

macropod
03-27-2012, 04:09 AM
Did you call it inaccurate because it doesn't provide the desirable results, or is there some other flaw?
I was referring to your own description:

It doesn't always work, sometimes it will return a value of several hundred points when there hardly is a difference at all between the columns.

MacroShadow
03-27-2012, 03:08 PM
Thank you.