Can I get a dll associated with a word doc to post a message box up front? 
Author Message
 Can I get a dll associated with a word doc to post a message box up front?

I've tried everything I can think of, and once again VB/VBA has stumped me.
Can anyone help?

I have a VB executable that asks a dll to open a Word document.  The user
edits the Word document, and the result gets placed in a RichTextBox in the
executable's form.  The intermediate dll knows about the Word application
and document.  I can trap close/save events in the dll and process things,
but how do I communicate with the user?  The dll doesn't present an
interface on its own.  Any message box I issue is buried under not just
Word, but any other windows that happen to be under Word.  as far as the
user is concerned, Word is frozen.  Word loads a template with some code in
it, butI can't trap anything before the document closes with this.  Asking
the executable to issue a message box has the same result.  Using
vbMsgBoxSetForeground doesn't work.  The only thing thatdoes is to set
vbSystemModal, which is a very unfriendly thing to do.

So how do I get message boxes to pop up?

I'll consider architecture changes if not too large.  And no, I didn't
design this.  I inherited it from a person who does not work with us any
more.

I don't care too much if the user has no choice about whether or not to save
the changes, but I need to trap the contents of Word being too large.



Thu, 03 Mar 2005 01:53:41 GMT  
 Can I get a dll associated with a word doc to post a message box up front?
The dll has obviously declared an object of type Word.Application, so you should
be able to get it to display a Word messagebox (as opposed to a messagebox
generated by the dll itself).

You didn't say what language the dll's code is in, but this sample works in VB6
(with a reference set to the Word object library):

Private Sub Command1_Click()
    Dim oWord As Word.Application
    Dim oDoc As Word.Document
    Set oWord = CreateObject("Word.Application")
    oWord.Visible = True
    Set oDoc = oWord.Documents.Add
    oWord.WordBasic.MsgBox "hello"
    oWord.Quit
    Set oDoc = Nothing
    Set oWord = Nothing
    End
End Sub

Oddly, the "native" VBA MsgBox function doesn't seem to be available through the
object library, so I had to use the one in the WordBasic object.

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word

Quote:

> I've tried everything I can think of, and once again VB/VBA has
> stumped me. Can anyone help?

> I have a VB executable that asks a dll to open a Word document.  The
> user edits the Word document, and the result gets placed in a
> RichTextBox in the executable's form.  The intermediate dll knows
> about the Word application and document.  I can trap close/save
> events in the dll and process things, but how do I communicate with
> the user?  The dll doesn't present an interface on its own.  Any
> message box I issue is buried under not just Word, but any other
> windows that happen to be under Word.  as far as the user is
> concerned, Word is frozen.  Word loads a template with some code in
> it, butI can't trap anything before the document closes with this.
> Asking the executable to issue a message box has the same result.
> Using vbMsgBoxSetForeground doesn't work.  The only thing thatdoes is
> to set vbSystemModal, which is a very unfriendly thing to do.

> So how do I get message boxes to pop up?

> I'll consider architecture changes if not too large.  And no, I didn't
> design this.  I inherited it from a person who does not work with us
> any more.

> I don't care too much if the user has no choice about whether or not
> to save the changes, but I need to trap the contents of Word being
> too large.



Thu, 03 Mar 2005 04:27:25 GMT  
 Can I get a dll associated with a word doc to post a message box up front?
Thanks for the quick reply.  The dll is in VB6.  Your scheme works once you
figure out the different syntax and response values.

Except...

I'm using this in two places, and the second one uses a string that is 321
characters long.  Itis a situation where we needto explain stuff pretty
thoroughly to the user, so it does needs to be this long.  Guess what?
"String too long"!

So close to the solution!  Any further thoughts?


Quote:
> The dll has obviously declared an object of type Word.Application, so you
should
> be able to get it to display a Word messagebox (as opposed to a messagebox
> generated by the dll itself).

> You didn't say what language the dll's code is in, but this sample works
in VB6
> (with a reference set to the Word object library):

> Private Sub Command1_Click()
>     Dim oWord As Word.Application
>     Dim oDoc As Word.Document
>     Set oWord = CreateObject("Word.Application")
>     oWord.Visible = True
>     Set oDoc = oWord.Documents.Add
>     oWord.WordBasic.MsgBox "hello"
>     oWord.Quit
>     Set oDoc = Nothing
>     Set oWord = Nothing
>     End
> End Sub

> Oddly, the "native" VBA MsgBox function doesn't seem to be available
through the
> object library, so I had to use the one in the WordBasic object.

> --
> Regards,
> Jay Freedman
> Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word


> > I've tried everything I can think of, and once again VB/VBA has
> > stumped me. Can anyone help?

> > I have a VB executable that asks a dll to open a Word document.  The
> > user edits the Word document, and the result gets placed in a
> > RichTextBox in the executable's form.  The intermediate dll knows
> > about the Word application and document.  I can trap close/save
> > events in the dll and process things, but how do I communicate with
> > the user?  The dll doesn't present an interface on its own.  Any
> > message box I issue is buried under not just Word, but any other
> > windows that happen to be under Word.  as far as the user is
> > concerned, Word is frozen.  Word loads a template with some code in
> > it, butI can't trap anything before the document closes with this.
> > Asking the executable to issue a message box has the same result.
> > Using vbMsgBoxSetForeground doesn't work.  The only thing thatdoes is
> > to set vbSystemModal, which is a very unfriendly thing to do.

> > So how do I get message boxes to pop up?

> > I'll consider architecture changes if not too large.  And no, I didn't
> > design this.  I inherited it from a person who does not work with us
> > any more.

> > I don't care too much if the user has no choice about whether or not
> > to save the changes, but I need to trap the contents of Word being
> > too large.



Thu, 03 Mar 2005 08:49:43 GMT  
 Can I get a dll associated with a word doc to post a message box up front?
Other than breaking the message into two pieces and showing them as consecutive
message boxes, I don't know any way around that.

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word

Quote:

> Thanks for the quick reply.  The dll is in VB6.  Your scheme works
> once you figure out the different syntax and response values.

> Except...

> I'm using this in two places, and the second one uses a string that
> is 321 characters long.  Itis a situation where we needto explain
> stuff pretty thoroughly to the user, so it does needs to be this
> long.  Guess what? "String too long"!

> So close to the solution!  Any further thoughts?



>> The dll has obviously declared an object of type Word.Application,
>> so you should be able to get it to display a Word messagebox (as
>> opposed to a messagebox generated by the dll itself).

>> You didn't say what language the dll's code is in, but this sample
>> works in VB6 (with a reference set to the Word object library):

>> Private Sub Command1_Click()
>>     Dim oWord As Word.Application
>>     Dim oDoc As Word.Document
>>     Set oWord = CreateObject("Word.Application")
>>     oWord.Visible = True
>>     Set oDoc = oWord.Documents.Add
>>     oWord.WordBasic.MsgBox "hello"
>>     oWord.Quit
>>     Set oDoc = Nothing
>>     Set oWord = Nothing
>>     End
>> End Sub

>> Oddly, the "native" VBA MsgBox function doesn't seem to be available
>> through the object library, so I had to use the one in the WordBasic
>> object.

>> --
>> Regards,
>> Jay Freedman
>> Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word


>>> I've tried everything I can think of, and once again VB/VBA has
>>> stumped me. Can anyone help?

>>> I have a VB executable that asks a dll to open a Word document.  The
>>> user edits the Word document, and the result gets placed in a
>>> RichTextBox in the executable's form.  The intermediate dll knows
>>> about the Word application and document.  I can trap close/save
>>> events in the dll and process things, but how do I communicate with
>>> the user?  The dll doesn't present an interface on its own.  Any
>>> message box I issue is buried under not just Word, but any other
>>> windows that happen to be under Word.  as far as the user is
>>> concerned, Word is frozen.  Word loads a template with some code in
>>> it, butI can't trap anything before the document closes with this.
>>> Asking the executable to issue a message box has the same result.
>>> Using vbMsgBoxSetForeground doesn't work.  The only thing thatdoes
>>> is to set vbSystemModal, which is a very unfriendly thing to do.

>>> So how do I get message boxes to pop up?

>>> I'll consider architecture changes if not too large.  And no, I
>>> didn't design this.  I inherited it from a person who does not work
>>> with us any more.

>>> I don't care too much if the user has no choice about whether or not
>>> to save the changes, but I need to trap the contents of Word being
>>> too large.



Thu, 03 Mar 2005 09:20:04 GMT  
 Can I get a dll associated with a word doc to post a message box up front?
Hi Can,

You can show the msgbox from within your vb application and after that set the focus to the word application:

-------------------------------------------------
 Sub Command1_Click()
 Dim sMsg As String

 sMsg = "The quick brown fox jumps over the lazy dog. " & _
         "The quick brown fox jumps over the lazy dog. " & _
         "The quick brown fox jumps over the lazy dog. " & _
         "The quick brown fox jumps over the lazy dog. " & _
         "The quick brown fox jumps over the lazy dog. " & _
         "The quick brown fox jumps over the lazy dog. " & _
         "The quick brown fox jumps over the lazy dog. " & _
         "The quick brown fox jumps over the lazy dog" & _
         vbCr & vbCr & "The final last line"
    Dim oWord As Word.Application
    Dim oDoc As Word.Document
    Set oWord = CreateObject("Word.Application")
    Set oDoc = oWord.Documents.Add
    MsgBox sMsg
    oWord.Visible = True
    oWord.Activate
    'oWord.Quit
    Set oDoc = Nothing
    Set oWord = Nothing
    End
End Sub
-------------------------------------------------

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/


Quote:
> Thanks for the quick reply.  The dll is in VB6.  Your scheme works once you
> figure out the different syntax and response values.

> Except...

> I'm using this in two places, and the second one uses a string that is 321
> characters long.  Itis a situation where we needto explain stuff pretty
> thoroughly to the user, so it does needs to be this long.  Guess what?
> "String too long"!

> So close to the solution!  Any further thoughts?



> > The dll has obviously declared an object of type Word.Application, so you
> should
> > be able to get it to display a Word messagebox (as opposed to a messagebox
> > generated by the dll itself).

> > You didn't say what language the dll's code is in, but this sample works
> in VB6
> > (with a reference set to the Word object library):

> > Private Sub Command1_Click()
> >     Dim oWord As Word.Application
> >     Dim oDoc As Word.Document
> >     Set oWord = CreateObject("Word.Application")
> >     oWord.Visible = True
> >     Set oDoc = oWord.Documents.Add
> >     oWord.WordBasic.MsgBox "hello"
> >     oWord.Quit
> >     Set oDoc = Nothing
> >     Set oWord = Nothing
> >     End
> > End Sub

> > Oddly, the "native" VBA MsgBox function doesn't seem to be available
> through the
> > object library, so I had to use the one in the WordBasic object.

> > --
> > Regards,
> > Jay Freedman
> > Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word


> > > I've tried everything I can think of, and once again VB/VBA has
> > > stumped me. Can anyone help?

> > > I have a VB executable that asks a dll to open a Word document.  The
> > > user edits the Word document, and the result gets placed in a
> > > RichTextBox in the executable's form.  The intermediate dll knows
> > > about the Word application and document.  I can trap close/save
> > > events in the dll and process things, but how do I communicate with
> > > the user?  The dll doesn't present an interface on its own.  Any
> > > message box I issue is buried under not just Word, but any other
> > > windows that happen to be under Word.  as far as the user is
> > > concerned, Word is frozen.  Word loads a template with some code in
> > > it, butI can't trap anything before the document closes with this.
> > > Asking the executable to issue a message box has the same result.
> > > Using vbMsgBoxSetForeground doesn't work.  The only thing thatdoes is
> > > to set vbSystemModal, which is a very unfriendly thing to do.

> > > So how do I get message boxes to pop up?

> > > I'll consider architecture changes if not too large.  And no, I didn't
> > > design this.  I inherited it from a person who does not work with us
> > > any more.

> > > I don't care too much if the user has no choice about whether or not
> > > to save the changes, but I need to trap the contents of Word being
> > > too large.



Fri, 04 Mar 2005 19:47:28 GMT  
 Can I get a dll associated with a word doc to post a message box up front?
I'm not sure we're at the same place, so I'll try to be clear.  The base exe
asks this dll to open Word.  When the Word document closes, the dll catches
the BeforeSave event and wants to emit two messages.  One of them is very
large.  (For now, I've cut the message down, but I would like to display the
whole thing.  Also, the WordBasic message box does not look the same.)

I have tried setting Word's visibility to false, but then whatever is below
Word shows up (probably the main exe, but could be something else the user
looked at recently).  I think this approach is OK for users who don't have a
lot of things open on their computers, but we can't be sure of that.  In
fact, our application is meant to work with several different Microsoft
programs at the same time.

Thanks.


Hi Can,

You can show the msgbox from within your vb application and after that set
the focus to the word application:

-------------------------------------------------
 Sub Command1_Click()
 Dim sMsg As String

 sMsg = "The quick brown fox jumps over the lazy dog. " & _
         "The quick brown fox jumps over the lazy dog. " & _
         "The quick brown fox jumps over the lazy dog. " & _
         "The quick brown fox jumps over the lazy dog. " & _
         "The quick brown fox jumps over the lazy dog. " & _
         "The quick brown fox jumps over the lazy dog. " & _
         "The quick brown fox jumps over the lazy dog. " & _
         "The quick brown fox jumps over the lazy dog" & _
         vbCr & vbCr & "The final last line"
    Dim oWord As Word.Application
    Dim oDoc As Word.Document
    Set oWord = CreateObject("Word.Application")
    Set oDoc = oWord.Documents.Add
    MsgBox sMsg
    oWord.Visible = True
    oWord.Activate
    'oWord.Quit
    Set oDoc = Nothing
    Set oWord = Nothing
    End
End Sub
-------------------------------------------------

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to
the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/



Fri, 04 Mar 2005 22:35:40 GMT  
 Can I get a dll associated with a word doc to post a message box up front?
Hi Can,

Did you try to use the MsgBox function without a reference to the objectvariable with the Word application? It only means the messagebox shows before the Word document (or application) shows.

I just don't seem to understand why this is not working with or without the need of showing the Word application itself. Did I misunderstood your question?

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/


Quote:
> I'm not sure we're at the same place, so I'll try to be clear.  The base exe
> asks this dll to open Word.  When the Word document closes, the dll catches
> the BeforeSave event and wants to emit two messages.  One of them is very
> large.  (For now, I've cut the message down, but I would like to display the
> whole thing.  Also, the WordBasic message box does not look the same.)

> I have tried setting Word's visibility to false, but then whatever is below
> Word shows up (probably the main exe, but could be something else the user
> looked at recently).  I think this approach is OK for users who don't have a
> lot of things open on their computers, but we can't be sure of that.  In
> fact, our application is meant to work with several different Microsoft
> programs at the same time.

> Thanks.



> Hi Can,

> You can show the msgbox from within your vb application and after that set
> the focus to the word application:

> -------------------------------------------------
>  Sub Command1_Click()
>  Dim sMsg As String

>  sMsg = "The quick brown fox jumps over the lazy dog. " & _
>          "The quick brown fox jumps over the lazy dog. " & _
>          "The quick brown fox jumps over the lazy dog. " & _
>          "The quick brown fox jumps over the lazy dog. " & _
>          "The quick brown fox jumps over the lazy dog. " & _
>          "The quick brown fox jumps over the lazy dog. " & _
>          "The quick brown fox jumps over the lazy dog. " & _
>          "The quick brown fox jumps over the lazy dog" & _
>          vbCr & vbCr & "The final last line"
>     Dim oWord As Word.Application
>     Dim oDoc As Word.Document
>     Set oWord = CreateObject("Word.Application")
>     Set oDoc = oWord.Documents.Add
>     MsgBox sMsg
>     oWord.Visible = True
>     oWord.Activate
>     'oWord.Quit
>     Set oDoc = Nothing
>     Set oWord = Nothing
>     End
> End Sub
> -------------------------------------------------

> Hope this helps,
> regards,
> Astrid

> So that all can benefit from the discussion, please post all follow-ups to
> the newsgroup.
> Visit the MVP Word FAQ site at http://www.mvps.org/word/



Sat, 05 Mar 2005 05:53:22 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Displaying a dialog box in front of Word

2. Getting Data From MS Word Doc

3. Getting Text from a word doc

4. Getting HTML body from Word Doc

5. Getting Word to open a doc with VBA

6. Template (Doc_New) not getting called w/ new doc - Word 2k

7. Combo Box in Word 2k Doc

8. Combo Box in Word 2k Doc

9. Replacing Text in Text Boxes in Word Doc from VB

10. Open word 97 doc with doc name as variable

11. Getting message content etc when MS Word is e-mail editor

12. Notifying users of a Posted message (at post time)

 

 
Powered by phpBB® Forum Software