projects


Word Macro - Short Lines

I created this VBA macro so that I could insert paragraph returns at suitable places in a doc in order that each line was no more than 80 characters (so that when I send it to bloomberg it formats properly).

Sub ShortLines()

‘ Author rrheaume

LineLength = 80 ‘change as required
BiggestWord = 25 ‘change as required

Limit = ActiveDocument.Characters.Count * 1.2 ‘ just incase something goes wrong!

Selection.HomeKey Unit:=wdStory

‘ clean the text up a bit and ID tabs which will be replaced with 4 spaces (ggg)

With Selection.Find
.Text = “^p”
.Replacement.Text = “^p^p”
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = “^p^t”
.Replacement.Text = “^pgggg ”
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = “^t”
.Replacement.Text = ” || ”
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

For Loops = 1 To ActiveDocument.Characters.Count / 40

‘ reset counters

RightMover = 0
SkipOver = 0
LeftMover = 0

‘ Move right until you get to a paragraph return or a count of 80
‘ If you get to a paragraph return skip over the next step and start over

For x = 1 To LineLength
If RightMover < LineLength Then
Selection.MoveRight Unit:=wdCharacter, Count:=1
RightMover = RightMover + 1
BigCounter = BigCounter + 1
If BigCounter > Limit Then Exit Sub
If Selection.Text = Chr(13) Then
SkipOver = 1
RightMover = LineLength + 1
End If
End If
Next x

‘ move left until you find a space character then insert a paragraph mark

If SkipOver = 0 Then
For Y = 1 To BiggestWord
If LeftMover < BiggestWord + 1 Then
Selection.MoveRight Unit:=wdCharacter, Count:=-1
If Selection.Text = Chr(13) Then LeftMover = BiggestWord + 1
If Selection.Text = " " Then
Selection.TypeParagraph
LeftMover = BiggestWord + 1
End If
LeftMover = LeftMover + 1
End If
Next Y

End If

Next Loops

' the rest just cleans up the text a bit

With Selection.Find
.Text = "^p "
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = " ^p"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll

For Y = 1 To 10
With Selection.Find
.Text = "^p^p^p"
.Replacement.Text = "^p^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll

Next Y

Selection.WholeStory
With Selection.ParagraphFormat
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
Selection.HomeKey Unit:=wdStory

' then we go back in an find the tab marker (gggg) and replace it with spaces

With Selection.Find
.Text = "^pgggg"
.Replacement.Text = "^p "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = "||"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = " "
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll

End Sub

Need Help with Outlook: View Reset Problem

I’ve looked everywhere and asked everyone so this is my last chance… that some anonymous surfer will come along with advice or find this in his search for the same thing.

Anytime I sort by a field (ie by clicking the relevant column heading) it redefines the view applied to the folder and removes the existing field grouping.

Eg: Let’s say I created the view “Fave View” which is available for all folders. I define the view so that it groups by the field [Categories] and sorts by [Received] - descending. I apply that view to my Inbox. Now some time later, while in my Inbox, I decide I want to sort by “Sender” so I click the top of the [Sender] column. *Poof* - the grouping disappears. I now just have a flat list sorted by [Sender].

To fix this, I go to apply the view {Fave View} again but nothing happens. When I go in to define {Fave View}, under the “group by” option it now shows “(none)” …? WTF? The {Fave View} has essentially been updated to reflect the last status of my inbox. It has been redefined.

Each folder seems to have its own version of the view… so the definition of “Fave View” for my sent folder still is grouped by [Categories].

Once upon a time, I could sort by any field while in the Inbox and it would not change the parameters of the view and the grouping would stay intact. Now the views have no permanence whatsoever and are redefined by every amendment I make to my active folder.

What can I do?

Nun komm, der Heiden Heiland: MP3

This is a recording of an amateur choir (Colibri) in Singapore performing JS Bach’s Nun komm, der Heiden Heiland. Again, the sound quality is poor but… well whatever. It’s worth every penny you pay.

Nun-komm.zip (5Mb)

This concert was held in early December 2005 at the Kampong Kapor Methodist Church and was sponsored by Artyfakt.

Uns Ist Ein Kind Geboren: MP3

This is a recording of an amateur choir (Colibri) in Singapore performing JL Bach’s Uns Ist Ein Kind Geboren. The sound quality is poor but the price is good: free.

Uns-Ist-Ein-Kind-Geboren.mp3 (10.3Mb)

This concert was held in early December 2005 at the Kampong Kapor Methodist Church and was sponsored by Artyfakt.

I believe this will mark the world premier of this piece being made available on the net! JL’s skill’s were somewhat weaker than his uncle so it’s understandable.

Previous Stories