Skip to content

derHoepp/WordHighlightSyntax

Repository files navigation

WordHighlightSyntax

VBA Project to add a VBA-Syntax-Highlighter to Word

Description

The VBA-Highlighter analyzes the contents of all #paragraphs with the #ParagraphStyle "Code" #periodically and highlights the Syntax of #Keywords, #Datatypes, #Strings and #Comments using #CharacterStyles. Custom Keywords are generally supported, as long as a corresponding #CharacterStyle exists. All #Keywords and #Datatypes are stored in an #ini-file. The identification of a #CharacterStyle is done by the name of a category inside of the #ini-file. Linebreaks and continuation are not supported

Basic Terms

#ini-file

The ini-file is structured having a categoryname inside square brackets [ ] followed by a vbCrLf, followed by a list of keywords split by vbCrLf. There must be no duplicates. E.g:

    [Keyword]
    For
    Each
    To
    Next
    [Datatype]
    String
    Integer
    Long
    [ManualHighlight]
    cKeyDict
    Todo
    cKeyword

A predefined ini-file is included as VBASyntax.ini

#Strings

String-literals are determined as any number of Characters between two DoubleQuotes inside a single Paragraph.

#Comments

Comments are determined as being the following Text after a Single Quote ' or after the Keyword Rem until the end of the paragraph. Single quotes or Rem inside double quotes are considered as being part of a string literal and thus not marked as Comment.

#Keywords, #DataTypes and #Customkeywords (KDCs)

keywords, datatypes and custom keywords are detected by iterating through all words inside a paragraph. KDCs are considered being part of a string literal if they appear inside double quotes. KDCs are considered being part of a comment if they are found after a single quote or Rem.

#Paragraphs

Paragraphs are determined by iterating through the built in Paragraphs()-Collection of a word Document-Object. Only Paragraphs with the #ParagraphStyle Code are considered.

#CharacterStyles

CharacterStyles for (built in) #Keywords, #Datatypes, #Comments and #Strings are mandatory and can be generated by the program itself. By default Keywords are styled in a dark-blue color, while Datatypes are shown in orange. Strings are lightly-blue colored, Comments green.

#ParagraphStyle Code

Only Paragraphs that are Styled with the "Code"-ParagraphStyle are considered as being relevant. The ParagraphStyle "Code" is mandatory and can be generated by the program itself. By default the Font is set to "Courier New", the FontSize to 11 and the margin between Paragraphs is set to 0. The rest of the style is derived from wdNormal.

UnitTests and Development

A testdriven approach to programming has been chosen. The tests are packed inside the Modules test.bas and UnitTests.bas. The Code is developed using RubberduckVBA.

About

VBA Project to add a VBA-Syntax-Highlighter to Word

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published