|
25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more... |
Home Projects Up Sitemap Search Blog Forum+Chat About Us Privacy Terms of Use Feedback FAQ Images Services Ads Donate Humor |
Microsoft Word 6.0 WordBasic macros to remove or transform carriage returns in filesManage carriage returns in a file. Change WordStar soft carriage returns to Word paragraph marks. Remove unwanted extra carriage returns from a file. Easily modified to do other transformations. |
|
Removes single hard carriage returns, but leaves double carriage returns to preserve paragraphs.
Sub MAIN
REM Copyright (C)1999 Steven Whitney.
REM Published under GNU GPL (General Public License) Version 2, with ABSOLUTELY NO WARRANTY.
REM REMOVES SINGLE HARD CARRIAGE RETURNS,
REM BUT LEAVES DOUBLE CARRIAGE RETURNS TO PRESERVE PARAGRAPHS.
REM
REM IT MAY BE POSSIBLE TO USE AUTOFORMAT TO DO THIS. TEST IT.
REM
REM IF YOUR SELECTION ENDS WITH A DOUBLE-CR, YOU SHOULD SELECT
REM THE DOUBLE-CR SO IT GETS PRESERVED AS A DOUBLE.
REM DON'T AVOID PROCESSING FINAL CRS BY ENDING YOUR SELECTION A LINE ABOVE.
REM (IF YOU DO, WHITESPACE ON LAST LINE WON'T GET REMOVED).
REM ----------------------------------------------------------------------------
REM YOU PROBABLY DON'T WANT TO DO THE WHOLE FILE. IF YOU DO, SELECT ALL FIRST.
If Len(Selection$()) <= 1 Then
MsgBox "You must select a block of text before calling this macro. If your selection ends with a double-CR, you should SELECT the double-cr so it gets preserved as a double.", "Cannot Continue", 48
Goto bye
EndIf
REM ----------------------------------------------------------------------------
REM 11-24-99 REMOVE LEADING and trailing WHITESPACE FROM EACH LINE SO IT DOESN'T GET
REM PULLED INTO THE TEXT, CREATING GAPS.
REM unsure which should be done first
REM TrimTrailingWhitespace 'don't use: it's unfinished & cancels selection
REM next line does the job
EditReplace .Find = "^w^p", .Replace = "^p", .Direction = 0, .MatchCase = 0, .WholeWord = 0, .PatternMatch = 0, .SoundsLike = 0, .ReplaceAll, .Format = 0, .Wrap = 0
TrimLeadingWhitespace 'this correctly only processes the selection
REM ----------------------------------------------------------------------------
REM The string used for CR$ must not appear in the file.
REM if macro aborts, change it to something else here.
REM CR$ = "~~" 'for reference if CR$ is temporarily changed
Let CR$ = "~~"
REM ----------------------------------------------------------------------------
REM IF SELECTION ALREADY CONTAINS OUR SUBSTITUTE PARAGRAPH MARK, QUIT
EditFind .Find = CR$, .Direction = 0, .MatchCase = 1, .WholeWord = 0, .PatternMatch = 0, .SoundsLike = 0, .Format = 0, .Wrap = 0
If EditFindFound() Then
MsgBox("This file already contains the string that this macro temporarily substitutes for double paragraph marks. You must modify the macro for use with this file.", "Cannot Run Macro", 64)
Goto bye
EndIf
REM ----------------------------------------------------------------------------
REM CHANGE ALL DOUBLE-CRS TO CR$ SO THEY GET PRESERVED IN THE NEXT STEP
EditReplace .Find = "^p^p", .Replace = CR$, .Direction = 0, .MatchCase = 0, .WholeWord = 0, .PatternMatch = 0, .SoundsLike = 0, .ReplaceAll, .Format = 0, .Wrap = 0
REM CHANGE ALL SINGLE CR TO SPACES SO PARAGRAPHS ARE ALLOWED TO WRAP.
EditReplace .Find = "^p", .Replace = " ", .Direction = 0, .MatchCase = 0, .WholeWord = 0, .PatternMatch = 0, .SoundsLike = 0, .ReplaceAll, .Format = 0, .Wrap = 0
REM PUT BACK THE DOUBLE-CRS
EditReplace .Find = CR$, .Replace = "^p^p", .Direction = 0, .MatchCase = 0, .WholeWord = 0, .PatternMatch = 0, .SoundsLike = 0, .ReplaceAll, .Format = 0, .Wrap = 0
bye:
End Sub
Changes soft (inside paragraph) CRs from WordStar files to hard Word CRs, in entire document. Sub MAIN REM 10-28-00 REM Copyright (C)2000 Steven Whitney. REM Published under GNU GPL (General Public License) Version 2, with ABSOLUTELY NO WARRANTY. REM Replaces all (interior) soft CRs from a WordStar Document mode document REM with MSWord hard Paragraph Marks. You must do this before running my REM RemoveHardCRs macro, for it to properly remove them all. REM This could use some enhancement. REM SEE CLEANSTRING$() FOR INSIGHT ON HOW WORD HANDLES cr AND lf StartOfDocument EditReplace .Find = "^0013^0013^0010", .Replace = "^p", .Direction = 0, .MatchCase = 0, .WholeWord = 0, .PatternMatch = 0, .SoundsLike = 0, .ReplaceAll, .Format = 0, .Wrap = 0 End Sub
|
|
|
|
|
|