Disabling alerts when opening Word.

306 views
Skip to first unread message

sbucci...@gmail.com

unread,
Aug 12, 2014, 3:01:50 PM8/12/14
to comfyj...@teamdev.com
Hi everyone,

I'm having an issue in some cases while trying to open a Word document. What happens is that if Word displays a messagebox, my application simply hangs. I'm there for looking for a way to start Word and tell Word not to display any sort of message. I found this C# code which seems to do what I want to do...

public Microsoft.Office.Interop.Word.Application wa = null;

wa
.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;

Any ideas on how I can do this in Java using ComfyJ?

Here is my Java code...

try
{
   
OleFunctions.oleInitialize();
} catch (Exception e) {
    log
.error("Unable to Initialize JniWrapper: " + e.getMessage());

   
throw new Exception("Unable to Initialize JniWrapper: " + e.getMessage());
}

_Application app
= Application.create(ClsCtx.LOCAL_SERVER);
app
.setVisible(new VariantBool(false));

_Document doc
= null;

try
{
    doc
= app.getDocuments().add(new Variant(WORKING_FOLDER + fileName + ".doc"),
           
Variant.createUnspecifiedParameter(),
           
Variant.createUnspecifiedParameter(),
           
Variant.createUnspecifiedParameter());
} catch (Exception e) {
   
if (doc != null) {
       
// Close the Word document.
        doc
.close(new Variant(WdSaveOptions.wdDoNotSaveChanges), Variant.createUnspecifiedParameter(), Variant.createUnspecifiedParameter());
        doc
= null;
   
}

   
if (app != null) {
       
// Close Microsoft Word.
        app
.quit(Variant.createUnspecifiedParameter(), Variant.createUnspecifiedParameter(), Variant.createUnspecifiedParameter());
        app
= null;
   
}

    log
.error("Unable to open DOC... " + WORKING_FOLDER + fileName + ".doc - (" + e.getMessage() + ")");

   
throw new Exception("Unable to open DOC... " + WORKING_FOLDER + fileName + ".doc - (" + e.getMessage() + ")", e);
}

Thanks!

Sergei Piletsky

unread,
Aug 13, 2014, 6:43:53 AM8/13/14
to Steve Bucciacchio, comfyj...@teamdev.com
Hi,

DisplayAlerts is a property of Application interface. In your Java code you are using  _Application COM Java wrapper that corresponds to the Microsoft.Office.Interop.Word.Application type in C#. In the _Application interface there is an appropriate setter and getter for that property that is generated in Java manner using set and get prefixes before property name. So, the Java code will be pretty much the same:
_Application app = Application.create(ClsCtx.LOCAL_SERVER);
app.setDisplayAlerts(new WdAlertLevel(WdAlertLevel.wdAlertsNone));

Sergei


--
You are receiving this email because you have joined the "ComfyJ Forum" group or have been added by request. You may choose not to receive emails from this group or unsubscribe completely on "Edit my membership" page.
Go to http://links.teamdev.com/comfyj-forum, choose "Edit my membership" link on the right. Specify your email preferences in suggested options, or click "Unsubscribe" button.
---
You received this message because you are subscribed to the Google Groups "ComfyJ Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to comfyj-forum...@teamdev.com.
To post to this group, send email to comfyj...@teamdev.com.
Visit this group at http://groups.google.com/a/teamdev.com/group/comfyj-forum/.
For more options, visit https://groups.google.com/a/teamdev.com/d/optout.

sbucci...@gmail.com

unread,
Aug 13, 2014, 3:14:28 PM8/13/14
to comfyj...@teamdev.com, sbucci...@gmail.com
Thanks a lot Sergei, much appreciated!
Reply all
Reply to author
Forward
0 new messages