WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: weissenb on August 18, 2013, 11:36:46 AM

Title: Replacing multiple formats in Word
Post by: weissenb on August 18, 2013, 11:36:46 AM
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" ############
Title: Re: Replacing multiple formats in Word
Post by: stanl on August 19, 2013, 03:33:03 AM
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()]
Title: Re: Replacing multiple formats in Word
Post by: Deana on August 19, 2013, 11:00:56 AM
Not sure but ObjectGet can be used to access an existing instance of the Word application object: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP/OLE~with~Word+OLE~and~Word~Example.txt
Title: Re: Replacing multiple formats in Word
Post by: 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
Title: Re: Replacing multiple formats in Word
Post by: Deana on August 21, 2013, 10:08:59 AM
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
Title: Re: Replacing multiple formats in Word
Post by: stanl on August 21, 2013, 10:21:46 AM
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.