[AccessD] Access RTF documents - post processing in Word

Borge Hansen pcs.accessd at gmail.com
Tue Jun 22 17:28:23 CDT 2021


Our long running event management access app has been making use of Word
macros for post processing of reports exported as RTF documents for the
past 20 years.

Back in the day when Word 2003 was the flavour of the year we would create
a number of Word macros / vba subs and then create another sub that would
simply run a number of these macros / call a number of these subs.

So for example in a .dot template file we would have a sub like this:
Sub PostProcessFormattingOfDocument()
' Code written 08/08/00 by bsh
    Application.Run macroname:="UnderlineFormat"
    Application.Run macroname:="BoldFormat"
    Application.Run macroname:="ItalicsFormat"
    Application.Run macroname:="NormalFormat"
    Application.Run macroname:="GreyBand"
    'one line added 20081116 / 20081210 bsh
    Application.Run macroname:="Lineseparator"
    Application.Run macroname:="ParagrLineSpacing4point75remove"
    Application.Run macroname:="ParagrLineSpacing5point25remove"
    Application.Run macroname:="ParagrLineSpacing12point65remove"
    Application.Run macroname:="ParagrLineSpacing13point7remove"
    'two lines added 20081210 bsh
    Application.Run macroname:="ParagrLineSpacing10point25remove"
    Application.Run macroname:="ParagrLineSpacing9point5remove"
    Application.Run macroname:="RemoveUnderlineFromTab"
    If MsgBox("End of general post processing of RTF document", vbOKOnly) =
vbOK Then
    End If
End Sub

In Word 2003 we would call this from a custom toolbar with a custom toolbar
menu item called
Format RTF Document
It would have the following description when hovering over the menu item:
"Macros: Post Process Formatting of Document"

User would attach the .dot template file and run the menu item from the
custom toolbar.
Nice and Easy.

In Word365 when we attach the old .dot template we get an "Add-ins" item on
the ribbon to the right of the Developer tab and the "Add-ins" show the
Custom Toolbars with all of our old custom toolbar menu items behind each
one is a certain vba sub / macro.

And that's fine - but there is no way I can replicate or modify the custom
toolbar in Word365.
I know, it's the same with Access - toolbars were given up when the Ribbon
was introduced, although toolbars in essence are used all over the place.

Now, please help - whoever can help me - How do we in Word365 create
something similar:
We do not want User to look at a number of macros - we want them - when
they attach a .dot or .dotm template - to be met with a better UI than just
a bunch of macros when all they need is to run a few subs or macros, that
each calls a number of macros as the example shows above.

The old Word 2003 with custom toolbars is sorely missed...

What's the best way to deal with this?
Customising the Ribbon by creating a custom item on the Developer tab I can
- with the .dot template file open - move a macro to the new custom item
and rename the reference to the macro. BUT this change is GLOBAL!  When I
open a blank document the new custom item is there - and I only want it to
be there when the User attaches the .dot template file. Clicking on the
custom item on a new open blank document of course just gives the
information that the macro can't be found or it has been disabled - crazy,
eh?

Arghh!

Anyone who can move me forward?

/borge

Note:
You may wonder what all the individual macros do and why?
Because rich text is lost from a report when exported to Word - that is all
rich text within a text control, we created a work around where User would
embed a text string that is to be bold in the post processed word format
with ~b and ~nb - similar for italics (~i / ~ni) and underline (~u / ~nu).
So the UnderlineFormat macro / sub would then run through the whole
document, format the embedded text strings and remove the homespun
formatting codes :

Sub UnderlineFormat()
' Code written  08/08/00 by Borge Steen Hansen
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "~u(*)~nu"
        .Replacement.Text = "\1"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Replacement.Font.Underline = wdUnderlineSingle
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub


More information about the AccessD mailing list