Problem on Word 2002

J

jlrc

[email protected] (jlrc) wrote in message news: said:
I have a VB add-in, in which I have implemented a custom
Yes/No/cancel option in OnNotCurrent() by following the 'PseudoClose'
event suggestions. i.e I send a an ESCAPE key event to the Word 'Do
you want to save dialog' thereby cancelling the close action. This has
been fine on word 2000 and 97.

But in word 2002/Office 10 I am having problems, the word save dialog doesn't
appear when I do a document close(through the lower X on the top right
hand corner). But appears when I do a word close(pressing the upper
'X' mark). Checked the ActiveDocument.Saved and its False in all cases before closing.

I am wondering if someone else had come across this problem before and
have some information about this.
 
P

Peter Hewett

Hi jpjlrc

Can't say for sure, but I'd take a guess that it's possibly the fact that
Office/Word 2002 supports an MDI interface and that the Escape key you're
sending is getting gobbled up by the wrong window.

HTH + Cheers - Peter


(e-mail address removed) (jlrc) wrote in
 
C

Chad DeMeyer

jlrc,

I have had lots of problems with trying to use SendKeys in conjunction with
built-in dialogs and alerts; especially, I have noticed that what works in
one version of Word may not work in another. My recommendation would be to
abandon the AutoClose approach and try to make the DocumentBeforeClose
approach work. I haven't tried the following when Word is loaded as an
automation object, but what has worked for me is an autoexec.main procedure
in my add-in (runs automatically when add-in is loaded) that registers the
EventClassModule (lifted straight from
http://msdn.microsoft.com/library/d...en-us/off2000/html/wohowApplicationEvents.asp)
in my add-in as an event handler for the application. Then the
DocumentBeforeClose procedure should fire as expected.

Regards,
Chad
 
J

jlrc

Chad,

Thanks to your inputs, I tried your solution but for me the
DocumentBeforeClose doesn't fire when I load it via automation. This
time I just invoked word from a simple VBScript(testauto.vbs), with a
global add-in placed in word's startup folder (mystartup.dot)
containing DocumentBeforeClose().

(testauto.vbs)

Dim Word, Doc, myText
myText = "Helllo world!"
Set Word = CreateObject("Word.Application")
Word.Visible = true
Set Doc = Word.Documents.Add
Word.Selection.Text = myText

(mystartup.dot Class Module) EventClassModule

Public WithEvents oApp As Word.Application

Private Sub oApp_DocumentBeforeClose(ByVal Doc As Document, Cancel As
Boolean)
MsgBox "mystartup.dot DocumentBeforeClose()"
Cancel = False
End Sub

(mystartup.dot Module) testMacros

Option Explicit

Dim X As New EventClassModule

Public Sub AutoExec()
Set X.oApp = Word.Application
MsgBox "mystartup.dot AutoExec()"
End Sub

I am not sure what I am missing here. Appreciate any help

Thanks
Rexi
 
C

Chad DeMeyer

Rexi,

Is your macro security set to High? If so, this may prevent the macros in
the Add-In from being enabled.

If that's not the problem (and I'm sure you probably already thought of
that), a few things you might try are:

1. Iterate through the Word.AddIns collection and check the .Installed
property in your script to see if mystartup.dot is even being loaded. If it
isn't, try forcing it to load with Word.AddIns.Add.
2. Instead of using testMacros.AutoExec, try using AutoExec.Main.
Theoretically it shouldn't make a difference, but worth a try.
3. If the Add-In is being loaded and just can't execute auto macros as a
member of an automation object (I haven't tried it myself), you might have
to move the code to register the application object variable out of the
AutoExec into a regular Sub and call it from your script (or wherever you
automate Word from in your final build). If it still doesn't work, we may
be forced to conclude that Word as an automation object can't respond to
application events.

Hope this moves you forward.
Regards,
Chad DeMeyer
 
J

jlrc

Hi,

Atlast we solved the problem. We found that there was another add-in
loaded which had the following code:

Sub DocClose()
'
' DocClose Macro
' Prompts to save the document and then closes the active window
'
WordBasic.DocClose

End Sub

When this code was removed, DocumentBeforeClose() fired for document
close and application close(in XP and Word 2000) and we could handle
our custom 'Do you want to save(Yes/NO/Cancel)'' here.

Thanks so much for all your inputs,
jlrc
 
C

Chad DeMeyer

Aha, it was the butler add-in with the candlestick in the dll library!
Thanks for passing this back, the knowledge may come in handy.

Regards,
Chad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top