Hello,
I am automating MS Word from the "outside' using a script and all is
well. Now I want to get Word to display a MsgBox actually in Word.

How do I call MsgBox to actually come up in Word when I am automating
from the outside?

(From looking through VBA's object inspector I found that MsgBox is a
member of the Interaction class, which is a member of the VBA class.
Can I access the VBA class when all I have in my script is a handle on
the Application class? Or am I barking up the wrong tree here)

Regards,
Matthew Lock

Re: Getting a MsBox when Automating Word from the Outside by Doug

Doug
Thu Nov 17 23:05:38 CST 2005

If a Word document is visible at the time the MsgBox is called, then the
MsgBox would appear in front of the Word document.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Matthew Lock" <lockster@gmail.com> wrote in message
news:1132285380.185698.73460@f14g2000cwb.googlegroups.com...
> Hello,
> I am automating MS Word from the "outside' using a script and all is
> well. Now I want to get Word to display a MsgBox actually in Word.
>
> How do I call MsgBox to actually come up in Word when I am automating
> from the outside?
>
> (From looking through VBA's object inspector I found that MsgBox is a
> member of the Interaction class, which is a member of the VBA class.
> Can I access the VBA class when all I have in my script is a handle on
> the Application class? Or am I barking up the wrong tree here)
>
> Regards,
> Matthew Lock
>



Re: Getting a MsBox when Automating Word from the Outside by Matthew

Matthew
Thu Nov 17 23:13:34 CST 2005


Doug Robbins - Word MVP wrote:
> If a Word document is visible at the time the MsgBox is called, then the
> MsgBox would appear in front of the Word document.

How do I actually call MsgBox though? From my script I can't simply
write "MsgBox" as the script will think that's a function in my script,
not a function of Word.

I have tried exploring through the Application object, but didn't find
anything there.

Thanks,
Matthew


Re: Getting a MsBox when Automating Word from the Outside by Tony

Tony
Fri Nov 18 07:08:25 CST 2005

You don't have access to VBA methods via the Word Application. If your
Script (you don't say what application or scripting language) doesn't have a
native MsgBox you will have to use APIs for a Windows message box.

--
Enjoy,
Tony


"Matthew Lock" <lockster@gmail.com> wrote in message
news:1132290814.854868.180980@z14g2000cwz.googlegroups.com...
>
> Doug Robbins - Word MVP wrote:
> > If a Word document is visible at the time the MsgBox is called, then the
> > MsgBox would appear in front of the Word document.
>
> How do I actually call MsgBox though? From my script I can't simply
> write "MsgBox" as the script will think that's a function in my script,
> not a function of Word.
>
> I have tried exploring through the Application object, but didn't find
> anything there.
>
> Thanks,
> Matthew
>



Re: Getting a MsBox when Automating Word from the Outside by mr_unreliable

mr_unreliable
Fri Nov 18 11:42:30 CST 2005

Er, wait.

vba has a msgbox function.

How about writing a word/vba/macro which calls the mb function.

Then from script, run the macro.

Note: you can find examples of running a vba macro from script
by searching the archives of this ng.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)


Re: Getting a MsBox when Automating Word from the Outside by Tony

Tony
Fri Nov 18 13:33:28 CST 2005

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


"mr_unreliable" <kindlyReplyToNewsgroup@notmail.com> wrote in message
news:u4ppqXG7FHA.3760@TK2MSFTNGP14.phx.gbl...
> Er, wait.
>
> vba has a msgbox function.
>
> How about writing a word/vba/macro which calls the mb function.
>
> Then from script, run the macro.
>
> Note: you can find examples of running a vba macro from script
> by searching the archives of this ng.
>
> cheers, jw
> ____________________________________________________________
>
> You got questions? WE GOT ANSWERS!!! ..(but,
> no guarantee the answers will be applicable to the questions)
>



Re: Getting a MsBox when Automating Word from the Outside by mr_unreliable

mr_unreliable
Sat Nov 19 12:24:22 CST 2005

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("myMsgBoxCode"))
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

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