Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default Re. Module Comments



As an additional contribution to a recent question about commentary inside
macros:

A good documentation on the code is a must in advanced programming.
Sometimes it is necessary to write a larger description. This may appear
either in a separate Word document, or may be, of course, placed as a usual
comment between Sub or Function, and End. In the last case it is a nuisance
to divide a written paragraph into lines of adequate length. Especially it
pains if one has to rewrite such a block. The following Subs have proven
useful to facilitate this work.

Both are Word macros, and thus they must be imported into Normal or other
module of that application. You can easily create a compact text of a comment
in Word, and after the appending the remark markers (apostrophe, or % for
Matlab) by means of MacroComment you can copy the rebuilt text into the code
page.

In revert, you can copy a selected remark block from a code to a Word
document, and by means of macro ConcatenateParagraph remove remark markers
and inner ends of paragraph, and thus prepare the text for changing and
replacing. You can work to and fro by switching both subroutines.

Another benefit of ConcatenateParagraph is removing, in the selected
paragraph, all the s that are appearing through a normal run of e-mail. In
such a way you can convert that mutilated messages into a human language.

Though this is aimed partly at Word groups, I offer this first here, hoping
to receive some comments from those interested.


Sub ConcatenateParagraph()
' Petr Bezucha, 2009
Dim Begin As Long
'selection of all the block to be arranged
With Selection
'Application.ScreenUpdating = False
Begin = .Start
'cursor after the last character of the selection
.Collapse (wdCollapseEnd)
Do
'repeating: selection of the whole line,
.MoveEnd Unit:=wdLine, Count:=-1
'selection of the first character in the line
.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
'deleting all 's and ' as first characters
Do
If .Text = "" Then .Delete Else Exit Do
Loop
If .Text = "'" Or .Text = "%" Then .Delete
.Collapse (wdCollapseStart)
'finish if strikes the beginning
If .Start <= Begin Then Exit Sub
'deleting end of paragraph
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Asc(.Text) = 13 Then .Delete
Loop
End With
'Application.ScreenUpdating = True
End Sub

Sub MacroComment()
' Petr Bezucha, 2009
Dim MB As String, RM As Single, Finish As Long, Begin As Long
Static ComMark As String
If ComMark = "" Then
MB = InputBox("' % Rem", "Marker of commentary line", "'")
If MB = "'" Or MB = "%" Then ComMark = MB Else Exit Sub
End If
With Selection
.Font.Name = "Courier New"
.ParagraphFormat.Alignment = wdAlignParagraphLeft
'diminishing of the line length by approx. one character space
RM = .PageSetup.RightMargin
.PageSetup.RightMargin = RM + .Font.Size
MB = MsgBox("Change font size or margin if necessary", _
vbOKCancel + vbQuestion, "Comment layout")
'exit with original line length
If MB = vbCancel Then .PageSetup.RightMargin = RM: Exit Sub
'number of the first character
Begin = .Start
'move to the very end of the paragraph
.EndKey Extend:=wdMove
'select the last character and if it is space, delete it
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If .Text = " " Then .Delete
'move to the beginning of the line
.HomeKey Unit:=wdLine, Extend:=wdMove
'add marker
.TypeText Text:=ComMark
Do
.MoveUp Unit:=wdLine, Extend:=wdMove
.EndOf Unit:=wdLine, Extend:=wdMove
.TypeParagraph
.MoveUp Unit:=wdLine, Count:=1, Extend:=wdMove
.TypeText Text:=ComMark
Loop While .Start Begin + 1
'return to the original line length
.PageSetup.RightMargin = RM
End With
End Sub

Thanks

Petr Bezucha
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Re. Module Comments

Thanks! Very useful.
Paul

On Apr 23, 2:31*pm, PBezucha
wrote:
As an additional contribution to a recent question about commentary inside
macros:

A good documentation on the code is a must in advanced programming.
Sometimes it is necessary to write a larger description. This may appear
either in a separate Word document, or may be, of course, placed as a usual
comment between Sub or Function, and End. In the last case it is a nuisance
to divide a written paragraph into lines of adequate length. Especially it
pains if one has to rewrite such a block. The following Sub’s have proven
useful to facilitate this work.

Both are Word macros, and thus they must be imported into Normal or other
module of that application. You can easily create a compact text of a comment
in Word, and after the appending the remark markers (apostrophe, or % for
Matlab) by means of MacroComment you can copy the rebuilt text into the code
page.

In revert, you can copy a selected remark block from a code to a Word
document, and by means of macro ConcatenateParagraph remove remark markers
and inner ends of paragraph, and thus prepare the text for changing and
replacing. You can work to and fro by switching both subroutines. *

Another benefit of ConcatenateParagraph is removing, in the selected
paragraph, all the ’s that are appearing through a normal run of e-mail. In
such a way you can convert that mutilated messages into a human language.

Though this is aimed partly at Word groups, I offer this first here, hoping
to receive some comments from those interested.

Sub ConcatenateParagraph()
' Petr Bezucha, 2009
Dim Begin As Long
'selection of all the block to be arranged
With Selection
* 'Application.ScreenUpdating = False
* Begin = .Start
* 'cursor after the last character of the selection
* .Collapse (wdCollapseEnd)
* Do
* * 'repeating: selection of the whole line,
* * .MoveEnd Unit:=wdLine, Count:=-1
* * 'selection of the first character in the line
* * .MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
* * 'deleting all *'s *and * ' as first characters
* * Do
* * * If .Text = "" Then .Delete Else Exit Do
* * Loop
* * If .Text = "'" Or .Text = "%" Then .Delete
* * .Collapse (wdCollapseStart)
* * 'finish if strikes the beginning
* * If .Start <= Begin Then Exit Sub
* * 'deleting end of paragraph
* * .MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
* * If Asc(.Text) = 13 Then .Delete
* Loop
End With
'Application.ScreenUpdating = True
End Sub

Sub MacroComment()
' Petr Bezucha, 2009
Dim MB As String, RM As Single, Finish As Long, Begin As Long
Static ComMark As String
If ComMark = "" Then
* MB = InputBox("' * % * *Rem", "Marker of commentary line", "'")
* If MB = "'" Or MB = "%" Then ComMark = MB Else Exit Sub
End If
With Selection
* .Font.Name = "Courier New"
* .ParagraphFormat.Alignment = wdAlignParagraphLeft
* 'diminishing of the line length by approx. one character space
* RM = .PageSetup.RightMargin
* .PageSetup.RightMargin = RM + .Font.Size
* MB = MsgBox("Change font size or margin if necessary", _
* * vbOKCancel + vbQuestion, "Comment layout")
* 'exit with original line length
* If MB = vbCancel Then .PageSetup.RightMargin = RM: Exit Sub
* 'number of the first character
* Begin = .Start
* 'move to the very end of the paragraph
* .EndKey Extend:=wdMove
* 'select the last character and if it is space, delete it
* .MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
* If .Text = " " Then .Delete
* 'move to the beginning of the line
* .HomeKey Unit:=wdLine, Extend:=wdMove
* 'add marker
* .TypeText Text:=ComMark
* Do
* * .MoveUp Unit:=wdLine, Extend:=wdMove
* * .EndOf Unit:=wdLine, Extend:=wdMove
* * .TypeParagraph
* * .MoveUp Unit:=wdLine, Count:=1, Extend:=wdMove
* * .TypeText Text:=ComMark
* Loop While .Start Begin + 1
* 'return to the original line length
* * .PageSetup.RightMargin = RM
End With
End Sub

Thanks

Petr Bezucha


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Module Comments jfcby Excel Programming 3 April 22nd 09 08:54 PM
VBA code in one Module referencing Public Variables Declared inanother Module failing Khurram Excel Programming 5 March 11th 09 11:01 PM
Need some comments on my Utility_Move class module. jchen Excel Worksheet Functions 0 August 21st 06 07:05 PM
code in module A to not execute a Worksheet_SelectionChange sub of another module Jack Sons Excel Discussion (Misc queries) 4 December 11th 05 11:52 PM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 05:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"