Word paras in 2 cols

F

Francis Hookam

Required:
To convert selected 10pt paragraphs from aligned left single column to 8pt
two column line between and to end by removing the indent on the first
paragraph. The selected paragraphs are in Normal format and the paragraph
above and below will usually be Heading 1 (so a TOC can be generated on
completion. I want to maintain the Heading 1s above and below the selection
as they are, that is single column stretching right across the page

A dry run works fine so the following macro was recorded (I have comment
blocked as much as I think can be omitted)

When run, the macro converts the whole of the remainder of the document, not
just the selected paragraphs!!!

Since there will be 10-20 separate selections to format this way each month
when I produce the club Newsround it would help to automate the job

Of course, if there were some way of the macro picking out Heading 1s and
then selecting the paras between, converting them and then proceeding down
the document that would be fantastic but I doubt that is possible (and might
take so much time programming as to be not worth bothering with ­ other than
the satisfaction of doing it!)

Many thanks if you can help

Francis Hookham
==========================================
Sub Columns()
With Selection.Font
' .Name = "Arial"
.Size = 8
' .Bold = False
' .Italic = False
' .Underline = wdUnderlineNone
' .UnderlineColor = wdColorAutomatic
' .StrikeThrough = False
' .DoubleStrikeThrough = False
' .Outline = False
' .Emboss = False
' .Shadow = False
' .Hidden = False
' .SmallCaps = False
' .AllCaps = False
' .Color = wdColorAutomatic
' .Engrave = False
' .Superscript = False
' .Subscript = False
' .Spacing = 0
' .Scaling = 100
' .Position = 0
' .Kerning = 0
' .Animation = wdAnimationNone
End With
' If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
' ActiveWindow.Panes(2).Close
' End If
' If ActiveWindow.ActivePane.View.Type <> wdPrintView Then
' ActiveWindow.ActivePane.View.Type = wdPrintView
' End If
With Selection.PageSetup.TextColumns
.SetCount NumColumns:=2
.EvenlySpaced = True
.LineBetween = True
.Width = InchesToPoints(2.76)
.Spacing = InchesToPoints(0.25)
End With
' Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
Selection.MoveLeft Unit:=wdCharacter, Count:=1
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
' .RightIndent = InchesToPoints(0)
' .SpaceBefore = 0
' .SpaceBeforeAuto = False
' .SpaceAfter = 0
' .SpaceAfterAuto = False
' .LineSpacingRule = wdLineSpaceSingle
' .Alignment = wdAlignParagraphJustify
' .WidowControl = True
' .KeepWithNext = False
' .KeepTogether = False
' .PageBreakBefore = False
' .NoLineNumber = False
' .Hyphenation = True
' .FirstLineIndent = InchesToPoints(0)
' .OutlineLevel = wdOutlineLevelBodyText
' .CharacterUnitLeftIndent = 0
' .CharacterUnitRightIndent = 0
' .CharacterUnitFirstLineIndent = 0
' .LineUnitBefore = 0
' .LineUnitAfter = 0
End With
End Sub
 
K

Klaus Linke

Hi Francis,

You'll need to insert continuous section breaks before and after the selection,
if you want to only change the selected text to two columns, and leave the rest
in one column.

Selecting everything between the previous and next Heading 1 isn't too hard. I
used two different ways in the macro below to move the start/end of the range.
And you could achieve the same thing with Find.

Then the macro inserts the continuous section breaks (but only if there aren't
already section breaks right after/before the Heading 1).

The rest of the macro below is a copy/paste from your code. The only thing I
changed was to replace
Selection.MoveLeft Unit:=wdCharacter, Count:=1
(which the macro recorder gave you) with
Selection.Collapse (wdCollapseStart)

If you have selected something, hitting the LeftArrow key (which usually moves
left one character) will collapse to the start of the selection.
The macro code you recorded does the same, but for someone who doesn't very well
know how Word works, the code might be confusing, since you don't really move
the selection to the left one character.

For the font and paragraph formatting (8 pt, justified), you might prefer to
apply some style with those characteristics, rather than manual formatting.

Regards,
Klaus



' Macro changes chapter to two columns,
' and does some re-formatting.
' Works if the IP or Selection is somewhere in the chapter.
Dim p As Paragraph
Dim rngChapter As Range
Dim rngBreak As Range
Set p = Selection.Paragraphs(1)
While p.Style <> _
ActiveDocument.Styles(wdStyleHeading1)
Set p = p.Previous
Wend
Set rngChapter = p.Next.Range
While rngChapter.Paragraphs.Last.Style <> _
ActiveDocument.Styles(wdStyleHeading1)
rngChapter.MoveEnd Unit:=wdParagraph, Count:=1
Wend
rngChapter.MoveEnd Unit:=wdParagraph, Count:=-1
rngChapter.Select
Set rngBreak = rngChapter.Duplicate
rngBreak.Collapse (wdCollapseStart)
' Insert continuous section break before,
' if there isn't a section break
If AscW(rngBreak.Characters.First) <> 12 Then
rngBreak.InsertBreak Type:=wdSectionBreakContinuous
End If
rngBreak.SetRange _
start:=rngChapter.End, _
End:=rngChapter.End
' Insert continuous section break after,
' if there isn't a section break
If AscW(rngBreak.Characters.First) <> 12 Then
rngBreak.InsertBreak Type:=wdSectionBreakContinuous
End If
' Now format the text/columns with the code you already have:
Selection.MoveStart Unit:=wdCharacter, Count:=1
With Selection.Font
.Size = 8
End With
With Selection.PageSetup.TextColumns
.SetCount NumColumns:=2
.EvenlySpaced = True
.LineBetween = True
.Width = InchesToPoints(2.76)
.Spacing = InchesToPoints(0.25)
End With
Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
Selection.Collapse (wdCollapseStart)
' Selection.MoveLeft Unit:=wdCharacter, Count:=1
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
End With
 
F

Francis Hookam

Many thanks Klaus for your macro which is just what I wanted - it works fine

I a sense on the same subject (but do reply under a new heading if you think
it will useful and best seen by more):

I want to put that macro WITHIN a Word document itself (not in Normal) so
the documnet can be moved to an iBook and/or a PC

OK I can insert a Module into the Project rather than Normal and I can run
it manually from Tools > Macro > Macros... but I cannot see how to assign
the macro to a key command - I suppose I cannot do that becasue it will be a
computer specific key command held in Normal and so not transferable - I do
not want to have to set up that key command in other computers

Nor can I find a way of assigning the macro to a button/object in the
document itself - might not be much use anyway becasue it would be scrolled
out of sight

A year or two ago I did exchanged postings about an XL toolbar generated by
the particular spreadsheet and opened and closed by it - the toolbar
included buttons which ran that spreadsheet's own macros - I never quite
mastered it - might be able to now with a bit more experience but I did not
keep the info

So do you know of any way of doing the same sort of thing in a Word document
- a temporary, document generated, floating toolbar with a button to run
some macros held in the document and so transportable to another computer?

Tall order?

Francis Hookham
 
K

Klaus Linke

Hi Francis,

Toolbars and keyboard shortcuts can be stored in a document just as well as
macros.
I want to put that macro WITHIN a Word document itself (not in Normal)
so the documnet can be moved to an iBook and/or a PC

OK I can insert a Module into the Project rather than Normal and I can run
it manually from Tools > Macro > Macros... but I cannot see how to assign
the macro to a key command

The reason probably is that, in the "Customize keyboard" dialog, you had
"Normal.dot" selected as the current customization context.

Since it wouldn't make sense to store a keyboard shortcut to a macro in the doc
in Normal.dot, the dialog didn't show you the macro.
So do you know of any way of doing the same sort of thing in a Word document
- a temporary, document generated, floating toolbar with a button to run
some macros held in the document and so transportable to another computer?

Tall order?

No! Just try it, and watch out what the dialogs show you.
When you create a new toolbar, you will be asked where it should be stored.
Simply choose your document.

But maybe you should reconsider your strategy. Your customizations won't work if
you have your security set to "high" or "very high", and even on "medium", the
constant questions on whether you trust your macros will get on your nerves.

If you put the customizations in a template that's stored in your template
folder, you don't have that problem. And you can make that template a global
template at any time, or attach it to some other document, whereas the
customizations in the document really only work in that one document.

Greetings,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Need help modifying code 0
Table of Content 1
TOC Help 0
TOC Problem 0
Macro does not make image in header higher 0
textColumns 1
A macro to increase line spacing 1
TOC problem 0

Top