Replacing multiple formats in Word

Started by weissenb, August 18, 2013, 11:36:46 AM

Previous topic - Next topic

weissenb

Hello!
Using the macro recorder and some knowledge for manual changing the code, I generated a VBA script (see below). The script makes multiple replacements in format (like "Anamnese", "Diagnosis", "Pathology" to the same words in bold).
The problem is that WORD is running as module in another software (the patient management software ARIA: "http://www.varian.com/us/oncology/radiation_oncology/aria"). So I (officially) do not know where the word file were stored and under which names. Using ALTF-F8 I can run VBA scripts (locally but not in the terminal server enviroment), but it would be easier to handle this with a WinBatch script.
Most WinBatch scripts (incorporating VBA or OLE) I saw, need the stored file. Is it possible to run that like the "original" VBA on an open document?

Many thanks for any help.

Greetings from Germany, Christian


Here's the VBA script:
' ########### START: Changing "Diagnosis" to Bold ###########
'
    Selection.Find.ClearFormatting
    With Selection.Find.Font
        .Bold = False
        .Italic = False
    End With
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Bold = True
    With Selection.Find
        .Text = "Diagnose:"
        .Replacement.Text = "Diagnosis"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
'
' ########### ENDE: Replacing "Diagnosis" ############

stanl

This begs 2 questions:  (1) are you able to make an OLE connection to the Word Document embedded as a module?  (2) Are you able to identify the Word Document from iterating all Windows/titles?
There are:  Application.ActiveDocument.Name and Application.ActiveDocument.Path  OLE properties which would help with a solution assuming 1 or 2 above were true [you would use GetObject() not CreateObject()]

Deana

Deana F.
Technical Support
Wilson WindowWare Inc.

weissenb

Thank you very much - I will try this way.

Alternatively, I have to find a way to copy the text into Word - but some words have to be written in bold.
Therefore: Is it possible to generate formatted text by Winbatch and then to copy this formatted text (some keywords are bold) into Word (simply using the clipboard)?

Thank you very much

Christian Weissenberger

Deana

Quote from: weissenb on August 21, 2013, 02:21:10 AM
Thank you very much - I will try this way.

Alternatively, I have to find a way to copy the text into Word - but some words have to be written in bold.
Therefore: Is it possible to generate formatted text by Winbatch and then to copy this formatted text (some keywords are bold) into Word (simply using the clipboard)?

Thank you very much

Christian Weissenberger

WinBatch doesn't handle text formatting. However the Word Object model may allow for this: see http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP/OLE~with~Word+Change~font~in~Word~Document.txt
Deana F.
Technical Support
Wilson WindowWare Inc.

stanl

Quote from: weissenb on August 21, 2013, 02:21:10 AM
Thank you very much - I will try this way.

Alternatively, I have to find a way to copy the text into Word -
Christian Weissenberger
Again, this begs the question that WB is connected to your Word Document. I would suggest:write a simple WB script to obtain all windows titles on the desktop and write them to a text file, run your app that loads the Word doc, then run the WB script and post the output here. It should allow us to verify whether GetObject() can be used to connect.