View Single Post
 
Old 06-09-2019, 11:52 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 VBA to change the number of columns in a document at a page break.

Can any kind soul offer guidance, please?
I use the following code to set up columns in a Word 2010 document
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
End Sub 'SetColsInWholeDoc
Having created text in the columns, I now want to insert a page break (I can do that in VBA), then "merge" the second and third columns into one column, so col 1 is the same size as one of the original three columns, and column 2 is double the width of the original ones.
I know what the widths should be, it's the code to use I'm struggling with.
Any clues, anyone?
I've tried setting column widths, but when I do it seems to apply the new widths to all of the current document.
I think I somehow need to sort of set a range which starts at the end of the current document (something like)
Code:
 Set rng = ActiveDocument.Content
  rng.Collapse Direction:=wdCollapseEnd
then set up a new two column page and adjust the column widths.
Any guidance on how to do this (or what I'm currently doing wrong!) would be gratefully accepted....
Reply With Quote