|
|
MS Word Macros - Tidy Up HTML Without Any Removals Sub tidyupHTMLredux() ActiveDocument.Select If Selection.Find.Execute("<" & mysearchstring, 0, 0) = True Then Do Selection.MoveLeft , 2 If Selection.Characters(1) <> vbCr Then Selection.MoveRight , 2 If Selection.Characters(1) <> "/" Then Selection.MoveLeft , 1 Selection.InsertBefore vbCr Selection.MoveRight , 2 End If Else: Selection.MoveRight , 2 End If
Selection.Characters(1).Select Selection.EndOf wdStory, wdExtend Loop While Selection.Find.Execute("<" & mysearchstring, 0, 0) = True End If End Sub
What this macro does: This macro will help you structure and organize your HTML code for greater "readability." The workings of this macro are very similar to the popular Tidy HTML tool for the NoteTab Light program. This macro will take any HTML document and "clean up" the code in an aesthetic way only. What I mean by aesthetic is this: the code will not be corrected for any errors, it will only be laid out on the screen in a more visually pleasing way. The macro will visually organize your HTML code to make it easier to read, to work with, to correct, to comment, etc. In other words, if you are prone to writing jumbled, unindented, run-on, run-together HTML code that piles upon itself in one large mass rather than in neatly spaced lines for each tag, then this macro will quickly format your HTML documents in a layout worthy of an HTML handbook. The following is a "demonstration" of the Tidy-Up macro: Before:
<DD><HR align=left width=550><TABLE width=600 border=0><TBODY><TR><TD width="44%"><UL><LI><FONT FACE="arial" SIZE=2>Translate documents into Spanish in compliance with State & Federal law</FONT><P></P><LI><FONT FACE="arial" SIZE=2>Format and proofread official LBUSD district correspondence</FONT><P></P><LI><FONT FACE="arial" SIZE=2>Maintain confidentiality with student files and other sensitive information</FONT><P></P></LI></UL></TD><TD width="56%"><UL><LI><FONT FACE="arial" SIZE=2>Provide consultation and analysis regarding speech disorders in Spanish speaking students</FONT><P> <DD> <HR align=left width=550> <TABLE width=600 border=0> <TBODY> <TR> <TD width="44%"> <UL> <LI> <FONT FACE="arial" SIZE=2>Translate documents into Spanish in compliance with State & Federal law</FONT> <P></P> <LI> <FONT FACE="arial" SIZE=2>Format and proofread official LBUSD district correspondence</FONT> <P></P> <LI> <FONT FACE="arial" SIZE=2>Maintain confidentiality with student files and other sensitive information</FONT> <P></P></LI></UL></TD> <TD width="56%"> <UL> <LI> <FONT FACE="arial" SIZE=2>Provide consultation and analysis regarding speech disorders in Spanish speaking students</FONT> <P>
Why I wrote this macro: I wrote this macro after becoming frustrated with the Tidy HTML freeware tool. The Tidy HTML tool will lay out your HTML code in an organized fashion, but it has the added disadvantage of also deleting, discarding, and/or trimming elements of code that it deems "unexpected" or unnecessary! Many times it will remove <P> tags without warning or without even notifying the user, thereby reducing the white space of a web page. On occasion I have used Tidy HTML to render my code more readable and to help find errors, only to angrily discover that Tidy HTML stripped the <P> tags that I had intentionally placed between tables or images or horizontal rules, thereby altering the way my web page displays in a web browser. So, to all of you who have experienced problems with Tidy HTML and its messages of "Discarding unexpected ___" or "Trimming empty ___," this one's for you! Now you can finally tidy HTML code without correcting the code! ...without altering the code! ...without removing tags! You can achieve the structure and layout you are looking for without any unexpected or unwanted changes. Hallelujah! Thanks for reading about my macro! -Kelly Comments? |
|
|
|