Sunday, 8 September 2013

Writing a word macro to organize chat logs

Writing a word macro to organize chat logs

I need some help writing a word macro to organize some chat logs. What I
want is to eliminate repeated consecutive occurrences of names, regardless
of timestamp. Besides this, each person will be using their own formatting
style (font, font color, etc.). So, what I have is:
[12:40] Steve: *style1*this is an example text.*/style1*
[12:41] Steve: *style1*this is another example text.*/style1*
[12:41] Steve: *style1*this is yet another example text.*/style1*
[12:45] Bob: *style2*some more text.*/style2*
[12:46] Bob: *style2*even more text.*/style2*
[12:47] Steve: *style1*yadda yadda yadda.*/style1*
The expected output would be:
[12:40] Steve: *style1*this is an example text.
this is another example text.
this is yet another example text.*/style1*
[12:45] Bob: *style2*some more text.
even more text.*/style2*
[12:47] Steve: *style1*yadda yadda yadda.*style1*
As of now, unfortunately, I know next to nothing of VBA for Applications.
I was thinking of maybe searching for the names by a regex pattern and
assigning them to a variable, comparing each match to the previous and, if
they're equal, deleting the latter. The problem is I'm not fluent in VBA,
so I don't know how to do what I want.
So far, all I've got is this:
Sub Organize()
Dim re As RegExp
Dim names As MatchCollection, name As Match
re.Pattern = "\[[0-9]{2}:[0-9]{2}\] [a-zA-Z]{1,20}:"
re.IgnoreCase = True
re.Global = True
Set names = re.Execute(ActiveDocument.Range)
For Each name In names
'This is where I get lost
Next name
End Sub
So, in the interest of solving this problem and me learning some VBA,
could I get some help?

No comments:

Post a Comment