Solved

Dim AppWord As New Word.Application hangs

Posted on 2010-11-25
10
909 Views
Last Modified: 2012-05-10
I am automating Microsoft Word 2007 SP2 from a Visual Basic 2010 WinForm app. I am using early binding, so I import the reference and then I run this line of code:

Dim AppWord As New Word.Application

This works 90% of the time but occassionally it hangs on that line. Any ideas why?
0
Comment
Question by:SETP
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 34212031
If you can afford it, Aspose it better then Automation: http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx
0
 

Author Comment

by:SETP
ID: 34212119
Thanks for your reply emoreau. Unfortunately we have an almost non-exsistant budget, so were forced to use Microsoft Office...
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34212181
Personally I don't know but try late binding:

dim appWord as object
...
set appword = createobject("word.application")

Chris
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34218713
When this code hangs, is there a Word instance running already?
0
 

Author Comment

by:SETP
ID: 34228500
Hi CodeCruiser, you know what, I think there is another instance of Word running. At least the last time it hung there was - I'm not sure if that's always the case. I'll keep an eye on it. Do you think that's the problem? That maybe it's not closing Word properly?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 34228906
Yes that is a very common issue. You may want to try and use the existing instance and if there is no active instance then create one. You can use this code

        Dim w As Microsoft.Office.Interop.Word.Application
        Try
             w = Runtime.InteropServices.Marshal.GetActiveObject("Word.Application")
        Catch
             w = New Microsoft.Office.Interop.Word.Application
        End Try
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34228907
Did late binding help or change the symptoms?

Chris
0
 

Author Closing Comment

by:SETP
ID: 34265056
Ok i've been testing it this whole week and I think your suggestion worked... Thanks
0
 

Author Comment

by:SETP
ID: 34265062
chris_bottomley, I didn't try your suggestion because CodeCruisers suggestion seems to have worked. Yours might be a possible fix too? If I run into problems again I will defintiely give it a try. Thanks for your support.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question