Re: Getting a MsBox when Automating Word from the Outside by Tony
Tony
Sat Nov 19 14:01:45 CST 2005
Yes that is possible but relies (since Word XP / 2002) on the users having
security set to trust access to the VB project, which is not a default
setting nor one an average user would themselves set.
Many solutions are dependent on the environment to an extent but using APIs
and a Windows Message box should always work. I would expect, however, that
the scripting language would have its own message box facility and that
would be the easiest one to use.
--
Enjoy,
Tony
"mr_unreliable" <kindlyReplyToNewsgroup@notmail.com> wrote in message
news:##QvuTT7FHA.3200@TK2MSFTNGP11.phx.gbl...
> Tony, I disagree with the notion that you must have your
> "msgbox macro" in some universal template, in order to call
> a msgbox macro from script.
>
> If fact, you can insert your "msgbox macro" code into word
> (or excel) from your script.
>
> Here is some sample code:
>
> --- <snip> ---
> Dim oWD : Set oWD = WScript.CreateObject("Word.Application.8")
>
> ' oWD.Visible = False ' (optional)
>
> With oWD.VBE.VBProjects("Normal")
>
> ' add a standard code module, returns a module object
> (vbComponent)...
> Set oVBModCode = .VBComponents.Add(vbext_ct_StdModule)
>
> ' name the standard code module,
> ' (so as to keep track of it, for later)...
> oVBModCode.Name = "myCodeModule"
>
> ' enter your code into the code module...
>
.VBComponents("myCodeModule").CodeModule.AddFromString(GetResource("myMsgBox
Code"))
> End With
> --- </snip> ---
>
> The above code was taken from a "wsf" file, which supports "resources".
> But that's not really necessary. You could hold the code in an
> ordinary string variable.
>
> You can then call your inserted macro, using the "run" method.
>
> --- <snip> ---
> ' call the macro the you just loaded into msWD...
> sResult = oWD.Run("ShowMessageBox") ' ("TestFunction")
> --- </snip> ---
>
> Oh, and you either need to define the relevant constants yourself,
> or else reference the msWD typelib:
>
> <reference object="Word.document" version="8.0" />
>
> cheers, jw
> ____________________________________________________________
>
> You got questions? WE GOT ANSWERS!!! ..(but,
> no guarantee the answers will be applicable to the questions)
>
>
>
> Tony Jollans wrote:
> > Yes, that would work if you are always using the same document (or
template)
> > or all users have a global template containing the code but that's far
from
> > guaranteed in most cases.
> >
> > --
> > Enjoy,
> > Tony